[pyar] Hola Mundo!

Emiliano Dalla Verde Marcozzi edvm en fedoraproject.org
Mie Dic 18 10:43:54 ART 2013


Bueno, mando mi hola mundo! Quería compartir este código donde 'hago
aparecer' variables
no definidas, en el scope de un método, SUPER antipythonico! pero cada vez
que me acuerdo de
esto, me da gracia xD.

# -*- coding: utf-8 -*-

import types


def abracadabra(function):
    """Make magic."""

    def wrapped(*args, **kwargs):

        scope = dict()
        scope.update(globals())
        scope.update(function.func_globals)
        scope['hello'] = "Hello"
        scope['world'] = "World"
        new_method  = types.FunctionType(function.func_code, scope)
        new_method.func_defaults = function.func_defaults

        return new_method(*args, **kwargs)

    return wrapped


@abracadabra
def say_hello():
    print("%s %s!" % (hello, world))


if __name__ == '__main__':
    say_hello()

-- 
"Code without tests is broken by design." - Jacob Kaplan-Moss
Broken code @ https://github.com/edvm
jabber: edvm en python.org.ar
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20131218/3c595b64/attachment.html>


More information about the pyar mailing list