Python: script's directory
I was looking for a solution, but have not found what I need.
Script path: /dir/to/script/script.py or C:\dir\script.py
Excepted result:
$ ./script.py
output: /dir/to/script
$ cd .. && ./script/script.py
output: /dir/to/script
Is there any f开发者_如何学Gounction in os module or something?
I mixed solutions and write:
print os.path.abspath(os.path.dirname(__file__))
But it's ugly. Is there better way?
os.path.realpath will give you the result:
os.path.dirname(os.path.realpath(__file__))
精彩评论