【问题标题】:ConfigParser library not working when using with python3与 python3 一起使用时,ConfigParser 库不起作用
【发布时间】:2018-10-20 00:38:33
【问题描述】:

我正在使用和导入 ConfigParaser

import ConfigParser
config = ConfigParser.RawConfigParser()
config.read('Config.properties')
timeout_val=config.get('Section', 'commandtimeout') 

并使用安装它,

pip install ConfigParser

运行 python 脚本时出现以下错误。

Traceback (most recent call last):
  File "system_offline.py", line 41, in <module>
    import ConfigParser
ImportError: No module named 'ConfigParser'

现在,我的问题是,如果在同一个系统上使用 python 2.7 运行同一个程序,上面的 import 语句没有问题。

想知道这个程序需要做什么才能在 python3 上运行?

编辑:在使用 python 2.7 时它可以工作,但在使用 python3 时,我遇到了上述错误。

【问题讨论】:

  • 您使用的是 Python 2 还是 Python 3?
  • python3 --version Python 3.5.2
  • 我编辑了这个问题。在我使用 python 的路径上,现在 python3 出错。

标签: python configparser


【解决方案1】:

ConfigParser 模块在 Python 3.0 中为 renamed to configparser

【讨论】:

【解决方案2】:

如果您使用的是 python 3,这将起作用,模块已重命名

导入配置解析器 config = configparser.RawConfigParser()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 2019-11-25
    • 2016-05-18
    • 2020-06-23
    相关资源
    最近更新 更多