Modify

Ticket #239 (new defect)

Opened 2 years ago

Using yaml.dump() after yaml.load() creates different document for block and folded literals

Reported by: ceremcem@… Owned by: xi
Priority: high Component: pyyaml
Severity: normal Keywords: yaml.load block folded literals
Cc:

Description

Hi,

With folded and block scalars, a document can not be loaded into python code and then dumped as the same. Why?

What I expect is like that:

# original document
a: |
  this is an 
  example
  block

b: > 
  this is another
  example
  block

Using this code:

f = open(original_document)
result = yaml.dump(yaml.load(f.read()))
f.write(result)

Expected result:

# expected result document
a: |
  this is an 
  example
  block

b: > 
  this is another
  example
  block
# real result
a: 'this is an

  example

  block

  '
b: 'this is another example block

  '

Yes, there are some other questions on the web ( http://stackoverflow.com/questions/8640959/how-can-i-control-what-scalar-form-pyyaml-uses-for-my-data) but accepted answers does not satisfy my needs.

Am I missing something?

Attachments

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from xi. Next status will be 'new'
The owner will be changed from xi to anonymous. Next status will be 'assigned'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.