Custom Query (121 matches)
Results (37 - 39 of 121)
| Ticket | Resolution | Summary | Owner | Reporter |
|---|---|---|---|---|
| #167 | worksforme | Please help saving dict to yaml | xi | anonymous |
| Description |
Hi, is there any way of saving dict to a file in yaml format? I'm using:
----------------------------------------
#!/usr/bin/python
import yaml
y = """
root:
- subject1:
desc: msg1
- subject2:
desc: msg2
"""
settings=yaml.load(y)
settings['root'][0]['subject1']['desc'] = "new msg"
print settings
f = open("temp", "w")
f.write(str(settings))
----------------------------------------
but failing miserably, contents of the temp file:
{'root': [{'subject1': {'desc': 'new msg'}}, {'subject2': {'desc': 'msg2'}}]}
expected result:
root:
- subject1:
desc: new msg
- subject2:
desc: msg2
Is there anything like yaml.save? Any help greatly appreciated!
Regards,
Tomas
|
|||
| #136 | invalid | Pure-python emitter fails emitting tag represented as a mapping | xi | julians@… |
| Description |
Hi, the following snippet will fail with PyYAML 3.08: #!/usr/bin/env python2.5
import yaml
Dumper = yaml.Dumper
class FooTag(yaml.YAMLObject):
yaml_dumper = Dumper
yaml_tag = u'!foo'
@classmethod
def to_yaml(cls, dumper, foo):
return dumper.represent_mapping(None,
{"foo": "bar"} )
print(yaml.dump(FooTag(), Dumper=Dumper))
The error message is: Traceback (most recent call last):
File "tag_not_specified.py", line 20, in <module>
print(yaml.dump(FooTag(), Dumper=Dumper))
File "(bogus file name)", line 175, in dump
File "(bogus file name)", line 165, in dump_all
File "yaml/representer.py", line 34, in represent
File "yaml/serializer.py", line 54, in serialize
File "yaml/serializer.py", line 109, in serialize_node
File "yaml/emitter.py", line 110, in emit
File "yaml/emitter.py", line 224, in expect_document_root
File "yaml/emitter.py", line 238, in expect_node
File "yaml/emitter.py", line 483, in process_tag
yaml.emitter.EmitterError: tag is not specified
(For some reason the file name in lines two and three of the trace is wrong, I've removed it here.) The above does work when using libyaml (try substituting CDumper). For what it's worth it will also work when to_yaml emits a scalar instead of a mapping. I've found that the following patch fixes the issue for me, but I don't understand the code well enough to know all implications of doing so. diff -ru PyYAML-3.08/lib/yaml/emitter.py PyYAML-3.08-patched/lib/yaml/emitter.py
--- PyYAML-3.08/lib/yaml/emitter.py 2008-12-31 05:24:15.000000000 +1030
+++ PyYAML-3.08-patched/lib/yaml/emitter.py 2009-07-03 13:58:11.000000000 +0930
@@ -480,7 +480,7 @@
self.prepared_tag = None
return
if tag is None:
- raise EmitterError("tag is not specified")
+ return
if self.prepared_tag is None:
self.prepared_tag = self.prepare_tag(tag)
if self.prepared_tag:
|
|||
| #132 | worksforme | PySyck does not dump dictionaries | xi | xl269@… |
| Description |
infinity0@xl269:~$ uname -a Linux xl269 2.6.30-1-amd64 #1 SMP Sun Jun 14 15:00:29 UTC 2009 x86_64 GNU/Linux infinity0@xl269:~$ python --version Python 2.5.4 infinity0@xl269:~$ python Python 2.5.4 (r254:67916, Feb 18 2009, 03:00:47) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.
'--- {}\n\n'
{1: 2}
'{1: 2}\n'
{1: 2} |
|||
