python语法:获取当前python脚本路径

版权声明:如需转载,请注明作者及出处 https://blog.csdn.net/qq_33317586/article/details/83652930

参考链接:http://blog.51cto.com/xpleaf/1736956

就是这段代码,说明一下:

root@server01:~# cat test.py 
import os

path = os.path.dirname(__file__)
path1 = os.path.dirname(os.path.abspath(__file__))
print 'The path is:',path
print 'The path1 is:',path1
root@server01:~# python test.py 
The path is: 
The path1 is: /root
root@server01:~# python /root/test.py 
The path is: /root
The path1 is: /root

猜你喜欢

转载自blog.csdn.net/qq_33317586/article/details/83652930