Modify ↓
Ticket #79 (closed defect: wontfix)
Multiple scalar values used as key creates Python hash error
| Reported by: | clay@… | Owned by: | xi |
|---|---|---|---|
| Priority: | normal | Component: | pyyaml |
| Severity: | normal | Keywords: | load list tuple hash |
| Cc: |
Description
The YAML specification suggests that a mapping can have a key made of more than one item, as in
? - Detroit Tigers - Chicago cubs : - 2001-07-23
However, when that data is imported via yaml.load(), PyYAML exits with a yaml.constructor.ConstructorError?, saying "found unacceptable key (list objects are unhashable)"
Is there a way to force multi-value keys to be processed as tuples instead of lists?
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

Yes, it's possible, using a custom constructor for yaml mappings.
For example, the following script
produces
{('Detroit Tigers', 'Chicago cubs'): [datetime.date(2001, 7, 23)]}