pzxbc

  在写python程序中,有可能需要获取当前运行脚本的路径。打包成exe的脚本和直接运行地脚本在获取路径上稍微有点不同。

 代码:

import os
import sys

config_name = \'myapp.cfg\'

# determine if application is a script file or frozen exe
if getattr(sys, \'frozen\', False):
application_path = os.path.dirname(sys.executable)
elif __file__:
application_path = os.path.dirname(__file__)

config_path = os.path.join(application_path, config_name)


分类:

技术点:

相关文章:

  • 2021-12-04
  • 2022-12-23
  • 2021-11-20
  • 2021-05-07
  • 2021-12-22
  • 2021-07-30
  • 2022-12-23
猜你喜欢
  • 2021-12-10
  • 2021-06-25
  • 2022-02-15
  • 2021-07-28
  • 2022-02-04
  • 2022-12-23
  • 2022-02-11
相关资源
相似解决方案