Ticket #58 (closed task: wontfix)

Opened 7 years ago

Last modified 7 years ago

Is there a way??

Reported by: john.mcginnis@… Owned by: xi
Priority: low Component: pyyaml
Severity: minor Keywords: style

Description (last modified by xi) (diff)

a = yaml.load("""
   name: John
   number: 111

print a
{'name': 'John', 'number': 111}

ok so if I do:

print yaml.dump(a) 
{name: John, number: 11}


print yaml.dump(a, default_flow_style=False)
name: John
number: 111

My question is, is there a variable in the code that could make the block style the default output without having to reference the style preference all the time?


Change History

comment:1 Changed 7 years ago by xi

  • Description modified (diff)

comment:2 Changed 7 years ago by xi

  • Status changed from new to closed
  • Resolution set to wontfix

There's no way to change the default behavior of the dumper, although you can create a subclass of Dumber with the desired behavior. In that case, yaml.dump(a, default_flow_style=False) will be replaced with yaml.dump(a, Dumper=MyDumper), which is hardly an improvement.

What about:

def my_dump(a):
    return yaml.dump(a, default_flow_style=False)



Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

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

Note: See TracTickets for help on using tickets.