os.path.realpath(path) 与os.getcwd()区别

os.path.realpath(path) 得到的是当前文件所在的目录
os.getcwd()得到的是当前工作目录:
  比如当前目录是/root/,得到的就是/root了
在linux上crontab默认的也是/root目录,可以进入用env看一下,所以代码里如果是os.getcwd()拿到的也是/root目录

1、cd到要执行的py文件的目录运行脚本
2、脚本里使用(os.path.dirname(os.path.realpath(__file__))

 

posted on 2021-01-13 11:34  牛气冲天  阅读(572)  评论(0编辑  收藏  举报