pyyaml

pyyaml: dumping without tags

I have >>> import yaml >>> yaml.dump(u'abc') "!!python/unicode 'abc'\n" But I want >>> import yaml >>> yaml.dump(u'abc', magic='something') 'abc\n' What magic param forces no tagging? ...

Change list formatting in PyYAML output

This is how PyYAML behaves on my machine: >>> plan = {'Business Plan': ['Collect Underpants', '?', 'Profit']} >>> print(yaml.dump(plan)) Business Plan: [Collect Underpants, '?', Profit] What I want instead is this output (both is valid YAML): Business Plan: - Collect Underpants - '?' - Profit Is there some kind of option that would...

PyYAML parse into arbitary object

I have the following Python 2.6 program and YAML definition (using PyYAML): import yaml x = yaml.load( """ product: name : 'Product X' sku : 123 features : - size : '10x30cm' weight : '10kg' """ ) print type(x) print x Which result...

How to deserialize an object with pyYaml using safe_load?

Having a snippet like this: import yaml class User(object): def __init__(self, name, surname): self.name= name self.surname= surname user = User('spam', 'eggs') serialized_user = yaml.dump(user) #Network deserialized_user = yaml.load(serialized_user) print "name: %s, sname: %s" % (deserialized_user.name, deserialized...

How to force PyYAML to load strings as unicode objects?

The PyYAML package loads unmarked strings as either unicode or str objects, depending on their content. I would like to use unicode objects throughout my program (and, unfortunately, can't switch to Python 3 just yet). Is there an easy way to force PyYAML to always strings load unicode objects? I do not want to clutter my YAML with !!p...

Dumping Collection to YAML file with PyYaml

Hi, I am writing a python application. I am trying to dump my python object into yaml using PyYaml. I am using Python 2.6 and running Ubuntu Lucid 10.04. I am using the PyYAML package in Ubuntu Package: http://packages.ubuntu.com/lucid/python/python-yaml My object has 3 text variables and a list of objects. Roughly it is something like...

How to default to CLoader in PyYaml.load

Is there any way to have the default loader for PyYaml be CLoader. So instead of having to do yaml.load(f, Loader=yaml.CLoader) It would just default to CLoader, so I could do: yaml.load(f) ...

yaml property value

I am using yaml file to store attribute and value. But some of the values need the current date to be appended. So how do I enter the value in yaml file, so that yaml parser can automatically recognise and substitute with current date I am using pyyaml and python ...

Preserve new lines in YAML

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 ...

Parse YAML and assume a certain path is always a string

I am using the YAML parser from http://pyyaml.org and I want it to always interpret certain fields as string, but I can't figure out how add_path_resolver() works. For example: The parser assumes that "version" is a float: network: - name: apple - name: orange version: 2.3 site: banana Some files have "version: 2" (which is interpret...

Does django grok YML ? django not loading fixtures YML file (yml is not a known serialization)

I have successfully created my first django project. I have two apps in my project foo and foobar. I have created a folder named 'fixtures' in each of the app folders. I have NOT specified a fixtures directory in my settings.yml, so (according to the docs), django should be looking in my {app}/fixtures folder. In the {app}/fixtures fo...

Appengine create and export yaml file

Hi, I´m having trouble in creating a file and export to .yaml. I´m using Google App Engine with Python 2.5. Don´t understand the Yaml doc´s, it makes me confused. What i want is to create a file and save it. It´s necessary to get entities from Models. class SaveYAML(webapp.RequestHandler): def post(self): user = db.Query(m...