Changes between Version 25 and Version 26 of PyYAMLDocumentation
- Timestamp:
- 05/12/06 05:06:16 (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PyYAMLDocumentation
v25 v26 291 291 ... return tuple.__new__(cls, [a, b]) 292 292 ... def __repr__(self): 293 ... return " %sd%s" % self293 ... return "Dice(%s,%s)" % self 294 294 295 295 >>> print Dice(3,6) 296 Dice(3,6) 297 }}} 298 299 The default representation for '''`Dice`''' objects is not nice: 300 {{{ 301 #!python 302 >>> print yaml.dump(Dice(3,6)) 303 304 !!python/object/new:__main__.Dice 305 - !!python/tuple [3, 6] 306 }}} 307 308 Suppose you want a '''`Dice`''' object to represented as '''`AdB`''' in YAML: 309 {{{ 310 #!python 311 >>> print yaml.dump(Dice(3,6)) 312 296 313 3d6 297 314 }}} … … 302 319 #!python 303 320 >>> def dice_representer(dumper, data): 304 ... return dumper.represent_scalar(u'!dice', u nicode(data))321 ... return dumper.represent_scalar(u'!dice', u'%sd%s' % data) 305 322 306 323 >>> yaml.add_representer(Dice, dice_representer) … … 332 349 ... """) 333 350 334 {'initial hit points': 8d4}351 {'initial hit points': Dice(8,4)} 335 352 }}} 336 353 … … 356 373 ... """) 357 374 358 {'damage': 5d10}375 {'damage': Dice(5,10)} 359 376 }}} 360 377 … … 470 487 - Ring of Teleportation 471 488 - Ring of Speed 489 472 490 right hand: 473 491 - Ring of Resist Fire
