Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
script:python:xtra2 [2011/08/08 13:55] alfred |
— (actual) | ||
|---|---|---|---|
| Línea 1: | Línea 1: | ||
| - | ====== Xtra (Python) 2 ====== | ||
| - | ===== Nuevos conceptos ===== | ||
| - | ==== Reflection ==== | ||
| - | <code Python> | ||
| - | # sin reflection: | ||
| - | Foo().hello() | ||
| - | |||
| - | # con reflection: | ||
| - | getattr(globals()['Foo'](), 'hello')() | ||
| - | </code> | ||
| - | ===== Pequeñas librerías ===== | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | ==== PyYAML ==== | ||
| - | * [[http://pyyaml.org/wiki/PyYAML]] | ||
| - | * {{script:python:pyyaml-3.10.zip|PyYAML}} | ||
| - | Para parsear documentos [[tags:yaml|YAML]]. | ||
| - | === Uso === | ||
| - | Agregaremos la librería. | ||
| - | <code python> | ||
| - | import yaml | ||
| - | </code> | ||
| - | Cargar un texto yaml: | ||
| - | <code python> | ||
| - | print yaml.load(""" | ||
| - | name: Vorlin Laruknuzum | ||
| - | sex: Male | ||
| - | class: Priest | ||
| - | title: Acolyte | ||
| - | hp: [32, 71] | ||
| - | sp: [1, 13] | ||
| - | gold: 423 | ||
| - | inventory: | ||
| - | - a Holy Book of Prayers (Words of Wisdom) | ||
| - | - an Azure Potion of Cure Light Wounds | ||
| - | - a Silver Wand of Wonder | ||
| - | """) | ||
| - | </code> | ||
| - | Crear un texto yaml: | ||
| - | <code python> | ||
| - | print yaml.dump({'name': "The Cloak 'Colluin'", 'depth': 5, 'rarity': 45, 'weight': 10, 'cost': 50000, 'flags': ['INT', 'WIS', 'SPEED', 'STEALTH']}) | ||
| - | </code> | ||
| - | === Notas === | ||
| - | * Para instalar, en el directorio: | ||
| - | <code> | ||
| - | $ sudo python setup.py install | ||
| - | </code> | ||