问题标签 [configparser]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1512 浏览

python - Python ConfigParser 元素转换为 CSV 参数

我有一个解析 csv 文件并生成 XML 文件的脚本。我必须为解析器提供的参数之一是分隔符,在我的例子中它不是逗号而是制表符。

此信息存储在我提取的配置文件中,然后传递给 csv 解析器。

但是我收到一个类型错误,说“分隔符”必须是 1 个字符的字符串。我检查了 ident 的类型,它是一个字符串,但它似乎没有将 \t 识别为选项卡。当我输入 ident = '\t' 或 delimiter = '\t' 时,它会起作用。如何从配置文件中正确获取值。

0 投票
2 回答
18342 浏览

python - 用 Python 修改 INI 文件

我有一个需要使用 Python 修改的 INI 文件。我正在研究该ConfigParser模块,但仍然遇到问题。我的代码是这样的:

但是在运行此代码后查看amcap.ini文件时,它保持不变。谁能告诉我我做错了什么?

0 投票
2 回答
1949 浏览

python - Python 2.7:“未解决的导入:ConfigParser”

我最近编写了一个 Python 2.7 脚本(在 Eclipse 上使用 PyDev),它利用了内置的 ConfigParser 模块,并且该脚本运行良好。但是当我将它导出并发送给同事时,他无法让它工作。即使我们使用完全相同的设置,他也会不断收到“未解决的导入:ConfigParser”错误。这不应该发生,因为 ConfigParser 是内置的。

我到处搜索,但似乎找不到任何可行的解决方案。任何帮助,将不胜感激。

0 投票
1 回答
4168 浏览

python - 使用 Python 模块 iniparse 从 INI 文件中删除部分和键?

我正在使用 Python 模块iniparse将密钥保存到 INI 文件,但我想知道是否有一种方法可以使用iniparse. 我知道可以使用ConfigParser并且iniparse向后兼容ConfigParser,但我不知道如何使用相同的iniparse对象执行删除。

0 投票
1 回答
1648 浏览

python - 扩展 configparser 类并在新类中使用配置解析器

所以我正在尝试创建一个已经在文件中读取并具有 configparser 的所有功能以及更多功能的类。代码如下所示:

它从另一个脚本中调用,如下所示:

错误说:TypeError: module.__init__() takes at most 2 arguments (3 given)我错过了什么,我怎样才能让“dkconfig”对象的所有实例在构造过程中都已经读入了“cluster.ini”文件?

0 投票
3 回答
14271 浏览

python - Creating a class with all the elements specified in a file using ConfigParser

I have created a .ini-like file with all the values which I need later in my program, see below:

I would like to read all these items into a single class and make it accessible from other parts of my python project. What I have so far is the code below:

I am new to python but I can still see lots of problem with my code:

  • I am forced to add a attribute for each item in my class file. and keep the configuration file and my class in sync all the time.
  • This class is not a singleton, therefore the reading/parsing will be done from wherever it is imported!
  • If a value is added to the config-file with is not defined in my class, it will probably crash!

How should I solve this problem instead? Can class attributes be created dynamically?

My class only need to read from the values, so no writing to the configuration file is needed!

0 投票
1 回答
291 浏览

python - python读取没有键值对的ini

我正在尝试读取如下所示的配置文件

请让我知道我该如何阅读,因为配置解析器抛出错误:

如果 configparser 无法解析,还有其他方法吗?

0 投票
2 回答
17354 浏览

python - ConfigParser 中的布尔值始终返回 True

这是我的示例脚本:

这是conf.ini

运行脚本时,它会打印True两次。为什么?应该是Falsesome_other_boolean设置为no

0 投票
2 回答
2388 浏览

python - 如何从配置文件中删除白色字符?

我想使用 python 修改 samba 配置文件。这是我的代码

但是配置文件包含选项卡,是否有可能忽略选项卡?

0 投票
2 回答
804 浏览

python - 为什么 ConfigParser 不立即写入磁盘?

给定以下脚本:

它只会将一个条目写入文件,如下所示:

但是,如果您取消注释 time.sleep(1),则会显示所有条目。奇怪的是(对我来说,无论如何),即使你调用了 write_stuff(),并且从 shell 快速连续调用脚本,也会发生这种情况。我认为一旦 Python 退出,任何要写入磁盘的内容都会写入磁盘。这是怎么回事?

环境:Mac OS X 10.8 上的 Python 2.7.3