configparser

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

假如想象 提交于 2020-01-30 12:30:28
问题 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

Python Config Parser can't find section?

左心房为你撑大大i 提交于 2020-01-24 23:39:47
问题 I'm trying to use ConfigParser to read a .cfg file for my pygame game. I can't get it to function for some reason. The code looks like this: import ConfigParser def main(): config = ConfigParser.ConfigParser() config.read('options.cfg') print config.sections() Screen_width = config.getint('graphics','width') Screen_height = config.getint('graphics','height') The main method in this file is called in the launcher for the game. I've tested that out and that works perfectly. When I run this code

How to exclude DEFAULTs from Python ConfigParser .items()?

江枫思渺然 提交于 2020-01-23 04:43:30
问题 I'm using ConfigParser to load in data from a configuration file as follows: test.conf: [myfiles] fileone: %(datadir)s/somefile.foo filetwo: %(datadir)s/nudderfile.foo load.py: import ConfigParser config = ConfigParser.ConfigParser({'datadir': '/tmp'}) config.read('test.conf') print config.items('myfiles') print config.get('myfiles', 'datadir') Output: $ python load.py [('datadir', '/tmp'), ('filetwo', '/tmp/nudderfile.foo'), ('fileone', '/tmp/somefile.foo')] /tmp I'm surprised that the

python 3 configparser.read() does not raise an exception when given a non-existing file

扶醉桌前 提交于 2020-01-13 11:30:12
问题 When I attempt to read a non-existing file using configparser.read, I think it ought to raise an exception. It doesn't. It returns an empty list instead. Obviously, I can test for an empty list and raise an exception. It just seems to me to be more intuitive and safer if the configparser.read raised a FileNotFound exception. jeffs@jeffs-laptop:~/nbmdt (blue-sky)*$ python3.6 Python 3.6.2 (default, Oct 2 2017, 16:51:32) [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux Type "help", "copyright",

Python ConfigParser wrapper

不想你离开。 提交于 2020-01-06 13:12:24
问题 I have a config file and i want to load the options dynamicaly by entering the section and the options name. For instance this is the config file contents. [templates] path = /full/path/to/template and the config.py file class Config(object): def __init__(self): self.config = ConfigParser.ConfigParser() self.config.read('config.ini') for section in self.config.sections(): self.__dict__[section] = dict() for k, v in self.config.items(section): self.__dict__[section][k] = v def from_options

ConfigParser.MissingSectionHeaderError when parsing rsyncd config file with global options

让人想犯罪 __ 提交于 2020-01-03 13:01:40
问题 A configuration file generally needs section headers for each section. In rsyncd config files a global section need not explicitly have a section header. Example of an rsyncd.conf file: [rsyncd.conf] # GLOBAL OPTIONS path = /data/ftp pid file = /var/run/rsyncdpid.pid syslog facility = local3 uid = rsync gid = rsync read only = true use chroot = true # MODULE OPTIONS [mod1] ... How to parse such config files using python ConfigParser ? Doing the following gives an erorr: >>> import

how to interpolate the section-name with configparser

泪湿孤枕 提交于 2020-01-03 03:34:07
问题 I'm using configparser to read configuration for a backup-system. one of the options (the output path) often includes the section-name itself. [DEFAULT] compression=gzip [foo] output=/Backups/foo/ [pizza] output=/BigDisk/Backups/ [bar] output=/Backups/bar/ Now I would like to get rid manually appending the section name, and instead would like to use string interpolation. Something like the following: [DEFAULT] compression=gzip output=/Backups/%(SECTION)s/ [foo] [pizza] output=/BigDisk/Backups

Python - ConfigParser - AttributeError: ConfigParser instance has no attribute '__getitem__'

大兔子大兔子 提交于 2020-01-01 05:06:05
问题 I am creating a quote of the day server. I am reading options from an INI file, whose text is below: [Server] host = port = 17 [Quotes] file=quotes.txt However, when I use ConfigParser, it gives me this error: Traceback (most recent call last): File "server.py", line 59, in <module> Start() File "server.py", line 55, in Start configOptions = parseConfig(filename) File "server.py", line 33, in parseConfig server = config['Server'] AttributeError: ConfigParser instance has no attribute '_

Keep ConfigParser output files sorted

久未见 提交于 2019-12-30 06:28:43
问题 I've noticed with my source control that the content of the output files generated with ConfigParser is never in the same order. Sometimes sections will change place or options inside sections even without any modifications to the values. Is there a way to keep things sorted in the configuration file so that I don't have to commit trivial changes every time I launch my application? 回答1: Looks like this was fixed in Python 3.1 and 2.7 with the introduction of ordered dictionaries: The standard

Keep ConfigParser output files sorted

北城以北 提交于 2019-12-30 06:28:32
问题 I've noticed with my source control that the content of the output files generated with ConfigParser is never in the same order. Sometimes sections will change place or options inside sections even without any modifications to the values. Is there a way to keep things sorted in the configuration file so that I don't have to commit trivial changes every time I launch my application? 回答1: Looks like this was fixed in Python 3.1 and 2.7 with the introduction of ordered dictionaries: The standard