[英]configparser: Not reading the file from the given path
Below is my python project structure in eclipse. 下面是我在Eclipse中的python项目结构。 I am using configparser to read a section in settings.config file.
我正在使用configparser来读取settings.config文件中的一部分。 The configparser is not parsing the file.
configparser未解析文件。 It shows No Section specified but I have correctly mentioned the section.
它显示未指定任何节,但我正确提到了该节。 I am creating a dockerfile and when I run docker-compose file, the path is shown as
我正在创建一个dockerfile,当我运行docker-compose文件时,路径显示为
/usr/local/lib/python3.6/site-packages/MyProject-0.0.1-py3.6.egg/Publisher/settings.config
/usr/local/lib/python3.6/site-packages/MyProject-0.0.1-py3.6.egg/Publisher/settings.config
MyProject
-Client
-__init__.py
-Main.py
-Publisher
-domain1
-domain2
-__init__.py
-config.py
-callconfig.py
-__init__.py
-settings.config
#config.py
import os.path as path
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import ConfigParser # ver. < 3.0
class Config(object):
def get(self, mykey):
config = ConfigParser()
configpath = path.join(path.split(path.dirname(path.abspath(__file__)))[0], "settings.config")
print (configpath)
config.read(configpath)
myvalue = config.get('mysection', mykey)
Just specify the parent folder path or just go one hierarchy up 只需指定父文件夹路径或仅向上一级
configpath = 'Publisher/settings.config'
config.read(configpath)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.