UNIX absolute path starts with '/', whereas Windows starts with alphabet 'C:' or '\'. Does python has a standard function to check if a path is absolute or relative? Or do I have to come up with a function using regular expression?
views:
199answers:
5
+4
A:
os.path.isabs
returns True
if the path is absolute, False
if not. The documentation says it works in windows (I can confirm it works in Linux personally).
os.path.isabs(my_path)
orangeoctopus
2010-07-23 16:47:57
+1
A:
import os.path
os.path.isabs('\home\user')
True
os.path.isabs('user')
False
Alex Bliskovsky
2010-07-23 16:49:09
+1
A:
And if what you really want is the absolute path, don't bother checking to see if it is, just get the abspath
:
import os
print os.path.abspath('.')
Wayne Werner
2010-07-23 16:51:40