Advertisement
Guest User

Untitled

a guest
May 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import sys, os
  2.  
  3. # Solution 1
  4. my_path = sys.path[0] if os.path.isdir(path) else os.path.dirname(path)
  5.  
  6.  
  7. # Solution 2
  8. #获取脚本文件的当前路径
  9. def cur_file_dir():
  10. #获取脚本路径
  11. path = sys.path[0]
  12. #判断为脚本文件还是py2exe编译后的文件,如果是脚本文件,则返回的是脚本的目录,如果是py2exe编译后的文件,则返回的是编译后的文件路径
  13. if os.path.isdir(path):
  14. return path
  15. elif os.path.isfile(path):
  16. return os.path.dirname(path)
  17. #打印结果
  18. print cur_file_dir()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement