[英]Python Configparser not reading file. Says file is not existing
I have project structure is like 我有项目结构就好
Root
|--config
|---settings.cfg
|--utilities
|---ConfigReader.py
ConfigReader.py ConfigReader.py
import ConfigParser
config = ConfigParser.ConfigParser()
try:
with open('./config/settings.cfg') as f:
config.readfp(f)
except IOError as e:
raise Exception('Error reading settings.cfg file. '+format(str(e)))
When run above ConfigReader.py, I get always; 当在ConfigReader.py上面运行时,我总是得到;
raise Exception('Error reading settings.cfg file. '+format(str(e)))
Exception: Error reading settings.cfg file. [Errno 2] No such file or directory: './config/settings.cfg'
I changed providing filepath with back slash/front slash and dots.None working to me. 我更改了提供带有反斜杠/正斜杠和点的文件路径。没有工作给我。
What Im doing wrong here? 我在这做错了什么?
read like this, also make sure that the file is in path. 像这样读,也要确保文件在路径中。
config = configparser.ConfigParser()
config.read('./config/settings.cfg')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.