Skip to content

Instantly share code, notes, and snippets.

@wjzhangq
Last active April 29, 2019 08:29
Show Gist options
  • Save wjzhangq/1fffd9f823900de8dc89579b85b32480 to your computer and use it in GitHub Desktop.
Save wjzhangq/1fffd9f823900de8dc89579b85b32480 to your computer and use it in GitHub Desktop.
def cur_file_dir():
# 获取脚本路径
path = sys.path[0]
# 判断为脚本文件还是py2exe编译后的文件,如果是脚本文件,则返回的是脚本的目录,如果是py2exe编译后的文件,则返回的是编译后的文件路径
if os.path.isdir(path):
return path
elif os.path.isfile(path):
return os.path.dirname(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment