Self-modifying Code

Do Re Mi chel La Si Do enleverlesO.OmcO at OmclaveauO.com
Thu May 19 15:49:46 EDT 2005


Hi, you, also !

A view, with a little difference :


def titi(par):
    if par>222:
        return par*2
    else:
        return par*10

print titi(123)
print titi(1234)

#now, change the function, "on instant"
txt="""def titi(par):
    if par>222:
        return str(par)*2
    else:
        return str(par)*5
"""
exec(txt,globals(),globals())

print titi(123)
print titi(1234)






Michel Claveau






More information about the Python-list mailing list