python 如何获取调用脚本的真实路径?
天蓬老师
天蓬老师 2017-04-18 10:26:29
0
2
500

这我的文件结果,但是我在命令行直接运行命令的时候,或是在别的地方调用脚本的时候,总是找不到文件?

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print (os.path.join(BASE_DIR,"排名.xls"))

df = read_excel(os.path.join("排名.xls"))

这个脚本不行~~在当前目录下是可以的,但是 退一级目录就不行了

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
PHPzhong

I didn’t realize you used 2os.path.dirname嘛?BASE_DIR 为/百度覆盖率,
而"排名.xls"的路径在/百度覆盖率/官网业务词目录下,os.path.join(BASE_DIR,"排名.xls")Of course they don’t exist

刘奇

It is estimated that if you are using Python2 on the windows platform, you will have this problem with Chinese file names

It is recommended to upgrade Python3 to solve...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!