pyyaml

How to configure YAML to create fresh log files instead of appending them?

二次信任 提交于 2019-12-11 06:05:42
问题 In a python logger implementation given below, each time I run my program, the logs are appended each time to the existing log files. How do I ensure that each time I run my application code, they are written to the fresh log file? Is it happening because I have set the RotatingFileHandler with backup count as 20 with each file size of 10MB? Should I convert it to simple file handler? I am using following yaml based log configuration in my python logger. 1 version: 1 2 3 formatters: 4 simple:

PyYAML interprets string as timestamp

血红的双手。 提交于 2019-12-11 03:11:41
问题 It looks as though PyYAML interprets the string 10:01 as a duration in seconds: import yaml >>> yaml.load("time: 10:01") {'time': 601} The official documentation does not reflect that: PyYAML documentation Any suggestion how to read 10:01 as a string? 回答1: Put it in quotes: >>> import yaml >>> yaml.load('time: "10:01"') {'time': '10:01'} This tells YAML that it is a literal string, and inhibits attempts to treat it as a numeric value. 回答2: Since you are using a parser for YAML 1.1, you should

How can I install the python module YAML without ROOT ACCESS ( 'easy_install' and 'pip' are not available)?

我与影子孤独终老i 提交于 2019-12-11 02:11:38
问题 I am trying to run a python script that calls the yaml module on a server. I only have writing permissions in my home directory. The server has Python 2.7.3 installed. I do not have root access. Also, neither pip nor easy_install are available. I have downloaded the package and tried to run python setup.py install --user which gives the error error: can't combine user with with prefix/exec_prefix/home or install_(plat)base How can I get this to work? 回答1: Setting up and using a virtualenv is

In Pyyaml, how to represent empty strings and lists in block style?

十年热恋 提交于 2019-12-11 01:38:10
问题 I have added representers for folded strings, literal strings as mentioned in Any yaml libraries in Python that support dumping of long strings as block literals or folded blocks?. I have also added representer to print a list in block style in the dumped yaml content. But the issue is that when the string is empty, i.e., "" or the list is empty, they appear in non-block style in the dumped YAML content. How do force the pyyaml dumper to output "" empty strings with ">" or "|" style and empty

PyYaml parses '9:00' as int

橙三吉。 提交于 2019-12-10 17:23:53
问题 I have a file with the following data: classes: - 9:00 - 10:20 - 12:10 (and so on up to 21:00) I use python3 and yaml module to parse it. Precisely, the source is config = yaml.load (open (filename, 'r')) . But then, when I print config , I get the following output for this part of data: 'classes': [540, 630, 730, 820, 910, 1000, 1090, 1180], The values in the list are ints. While previously, when I used python2 (and BaseLoader for YAML), I got the values as strings, and I use them as such.

How can I add a python tuple to a YAML file using pyYAML?

痴心易碎 提交于 2019-12-10 04:17:11
问题 The title is fairly self-explanatory. When I save a tuple to a YAML file, I get something that looks like this: ambient: !!python/tuple [0.3, 0.3 ,0.3] When I try to load it with yaml.safe_load(file_object), I keep getting an error that reads: yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:python/tuple' What needs to be done? 回答1: In pyyaml, the SafeLoader does not include a loader for the python native types, only the types defined in the

PyYAML : Control ordering of items called by yaml.load()

北城以北 提交于 2019-12-10 01:21:31
问题 I have a yaml setting file which creates some records in db: setting1: name: [item,item] name1: text anothersetting2: name: [item,item] sub_setting: name :[item,item] when i update this file with setting3 and regenerate records in db by: import yaml fh = open('setting.txt', 'r') setting_list = yaml.load(fh) for i in setting_list: add_to_db[i] it's vital that the order of them settings (id numbers in db) stay the same each time as im addig them to the db... and setting3 just gets appended to

Preserve new lines in YAML

末鹿安然 提交于 2019-12-09 02:12:17
问题 How do I format a YAML document like this so that PyYAML can parse it properly? Data: Some data, here and a special character like ':' Another line of data on a separate line I know that the ':' character is special so I have to surround the whole thing in quotations like so: Data: "Some data, here and a special character like ':' Another line of data on a separate line" And in order to add a new line, I have to add '\n': Data: "Some data, here and a special character like ':'\n Another line

What does deep=True do in pyyaml.Loader.construct_mapping?

旧时模样 提交于 2019-12-08 04:37:43
问题 In searching around the web for usages of custom constructors I see things like this: def some_constructor(loader, node): value = loader.construct_mapping(node, deep=True) return SomeClass(value) What does the deep=True do? I don't see it in the pyyaml documentation. It looks like I need it; I have a yaml file generated by a pyyaml representer and it includes node anchors and aliases (like &id003 and *id003 ); without deep=True I get a shallow map back for those objects containing anchors

What does deep=True do in pyyaml.Loader.construct_mapping?

大兔子大兔子 提交于 2019-12-07 02:43:27
In searching around the web for usages of custom constructors I see things like this: def some_constructor(loader, node): value = loader.construct_mapping(node, deep=True) return SomeClass(value) What does the deep=True do? I don't see it in the pyyaml documentation . It looks like I need it; I have a yaml file generated by a pyyaml representer and it includes node anchors and aliases (like &id003 and *id003 ); without deep=True I get a shallow map back for those objects containing anchors/aliases. That you don't see deep=True in the documentation is because you don't normally need to use it