configparser

Python configparser will not accept keys without values

穿精又带淫゛_ 提交于 2021-02-18 19:55:10
问题 So I'm writing a script that reads from a config file, and I want to use it exactly how configparser is designed to be used as outlined here: http://docs.python.org/release/3.2.1/library/configparser.html I am using Python 3.2.1. The script, when complete, will run on a Windows 2008 R2 machine using the same version of Python, or assuming compatibility, the latest version at the time. #!/user/bin/env python import configparser config = configparser.ConfigParser() config.read('c:\exclude.ini')

ConfigParser - print config.sections() returns []

99封情书 提交于 2021-02-08 06:48:52
问题 I'm trying to use a ConfigParser module to parse an *.ini file. The problem is that when I try to print sections or whatever, it returns empty list [] . config.ini [SERVER] host=localhost port=9999 max_clients=5 [REGULAR_EXPRESSIONS] regular_expressions_file_path=commands/commands_dict config.py # -*- coding: utf-8 -*- import ConfigParser config = ConfigParser.SafeConfigParser() config.read("config.ini") print config.sections() [] Do you know where is the problem? EDIT: Here is a screen of my

ConfigParser - print config.sections() returns []

人盡茶涼 提交于 2021-02-08 06:48:52
问题 I'm trying to use a ConfigParser module to parse an *.ini file. The problem is that when I try to print sections or whatever, it returns empty list [] . config.ini [SERVER] host=localhost port=9999 max_clients=5 [REGULAR_EXPRESSIONS] regular_expressions_file_path=commands/commands_dict config.py # -*- coding: utf-8 -*- import ConfigParser config = ConfigParser.SafeConfigParser() config.read("config.ini") print config.sections() [] Do you know where is the problem? EDIT: Here is a screen of my

How to store and retrieve a dictionary of tuples in config parser python?

♀尐吖头ヾ 提交于 2021-01-28 08:04:45
问题 I'm using the configparser library in python to manage my configuration files. But, I can't find a method to store and retrieve tuples data-structure through it. My data is a dictionary of tuples. name_mapper = { 0 = (0, 0) 1 = (0, 1) 2 = (0, 2) 3 = (1, 0) 4 = (1, 1) 5 = (1, 2) 6 = (2, 0) 7 = (2, 1) 8 = (2, 2) 9 = (3, 0) 10 = (3, 1) 11 = (3, 2) } When I write this dictionary via configparser, everything becomes a string. myconfig.ini [NAME_MAPPER] 0 = (0, 0) 1 = (0, 1) 2 = (0, 2) 3 = (1, 0) 4

How to remove a section from an ini file using Python ConfigParser?

拟墨画扇 提交于 2020-07-08 06:58:26
问题 I am attempting to remove a [section] from an ini file using Python's ConfigParser library. >>> import os >>> import ConfigParser >>> os.system("cat a.ini") [a] b = c 0 >>> p = ConfigParser.SafeConfigParser() >>> s = open('a.ini', 'r+') >>> p.readfp(s) >>> p.sections() ['a'] >>> p.remove_section('a') True >>> p.sections() [] >>> p.write(s) >>> s.close() >>> os.system("cat a.ini") [a] b = c 0 >>> It appears that the remove_section() happens only in-memory and when asked to write back the

Python模块-configparser模块

五迷三道 提交于 2020-03-01 07:25:24
配置文件解析模块 生成配置文件 configparser.ConfigParser() 实例化对象 模拟生成samba配置文件,以字典形式存储和读取 # -*- coding:utf8 -*- import configparser config = configparser.ConfigParser() #实例化对象 config["global"] = { #配置信息 'workgroup':'SAMBA', 'security':'user', 'passdb backend':'tdbsam', 'printing':'cups', 'printcap name':'cups', 'load printers':'yes', 'cups options':'raw', } config["home"] = { #配置信息 'comment':'This is test !!!', 'browseable':'No', 'read only':'No', 'inherit acls':'Yes' } with open("smb.conf","w") as smb_config: #将配置信息写入文件 config.write(smb_config) 生成的配置文件 [global] workgroup = SAMBA security = user passdb

How to create, update and delete airflow variables without using the GUI?

会有一股神秘感。 提交于 2020-01-30 12:31:27
问题 I have been learning airflow and writing DAGs for an ETL pipeline. It involves using the AWS environment (S3, Redshift). It deals with copying data from one bucket to another after storing it in redshift. I am storing bucket names and prefixes as Variables in airflow for which you have to open the GUI and add them manually. Which is the most safest and widely used practice in the industry out of the following options Can we use airflow.cfg to store our variables ( bucket names ) and access