天天看點

Python os.path.abspath、os.path.dirname、os.path.join

[email protected]:~/workspace/gsgl/xxx/src/tools2.0/sql_gen$ cat rudy_try.py 

import os, sys
abs_dir=os.path.abspath(__file__)
top_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
inc_dir = os.path.join(top_dir, 'xxxx')
print "os.path.abspath(__file__):"+abs_dir
print "top_dir:"+top_dir
print "inc_dir:"+inc_dir

[email protected]:~/workspace/gsgl/xxx/src/tools2.0/sql_gen$ python rudy_try.py 

os.path.abspath(__file__):/home/rudy/workspace/gsgl/xxx/src/tools2.0/sql_gen/rudy_try.py
top_dir:/home/rudy/workspace/gsgl/xxx/src
inc_dir:/home/rudy/workspace/gsgl/xxx/src/xxxx