Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving up one directory in Python

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

like image 301
user2165857 Avatar asked Jul 26 '13 15:07

user2165857


People also ask

How do you move a parent directory in Python?

Using os.os. path. abspath() can be used to get the parent directory.


2 Answers

>>> import os >>> print os.path.abspath(os.curdir) C:\Python27 >>> os.chdir("..") >>> print os.path.abspath(os.curdir) C:\ 
like image 144
Ryan G Avatar answered Sep 20 '22 00:09

Ryan G


Using os.chdir should work:

import os os.chdir('..') 
like image 26
Steve Allison Avatar answered Sep 21 '22 00:09

Steve Allison