Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixing '../../' paths in python

Tags:

Is there an easy way in Python to resolve path operators like ..? For instance is there a function call that will convert: /../../test/../path to /path?

like image 489
rook Avatar asked Jan 13 '11 19:01

rook


People also ask

How do I change the path of a file in Python?

Changing the Current Working Directory in Python To change the current working directory in Python, use the chdir() method. The method accepts one argument, the path to the directory to which you want to change. The path argument can be absolute or relative.

Can we reset Python path?

1 Answer. Or probably just export PATH="/usr/bin:$PATH" would work, since you probably just need python to be found in that directory before the anaconda directories which are at the start of your path.


1 Answers

You can use os.path.realpath() to get the canonical path. To get a normalised relative path, use os.path.normpath().

like image 110
Sven Marnach Avatar answered Oct 26 '22 09:10

Sven Marnach