Is there a simple way to move up one directory in python using a single line of code? Something similar to cd ..
in command line
Using os.os. path. abspath() can be used to get the parent directory.
>>> import os >>> print os.path.abspath(os.curdir) C:\Python27 >>> os.chdir("..") >>> print os.path.abspath(os.curdir) C:\
Using os.chdir
should work:
import os os.chdir('..')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With