Skip to content

Instantly share code, notes, and snippets.

@ayuLiao
Created January 25, 2019 05:43
Show Gist options
  • Select an option

  • Save ayuLiao/ffd0470fab7ee8b8967bbccf69ebc6ff to your computer and use it in GitHub Desktop.

Select an option

Save ayuLiao/ffd0470fab7ee8b8967bbccf69ebc6ff to your computer and use it in GitHub Desktop.
python在导入数据时,使用当前python文件路径加上相对于当前文件的路径是比较好的方案
realpath = os.path.realpath(__file__) # 当前py文件路径
current_path = os.path.dirname(realpath) # 当前py所在的文件夹
globalconf = current_path+'/config/global.json'
with open(globalconf, 'r') as f:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment