相关疑难解决方法(0)

在python中访问资源文件的方法

在python程序中访问资源的正确方法是什么.

基本上在我的许多python模块中,我最终编写的代码如下:

  DIRNAME = os.path.split(__file__)[0]

  (...) 

  template_file = os.path.join(DIRNAME, "template.foo")
Run Code Online (Sandbox Code Playgroud)

哪个好,但是:

  • 如果我开始使用python zip包,它会破裂
  • 它是样板代码

在Java中,我有一个完全相同的函数 - 但是当代码位于一堆文件夹中时以及它被打包在.jar文件中时都可以工作.

在Python中是否有这样的功能,或者我可能使用其他任何模式.

python

28
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×1