CONSTRUCT - Python's way of Ruby's "alias_method"

Ilias Lazaridis ilias at
Thu Jun 8 14:28:39 CEST 2006

I have a few small questions subjecting python functionality, most 
importantly the "alias_method".



I would like to know, if this construct is valid, or if it can result in 
problems (that I do not see as a newcomer):

      1082    try:
      1083        from django.rework.evolve import evolvedb
      1084    except ImportError:
      1085        def evolvedb():
      1086            "Evolve Command Dummy"
      1087            print 'Command evolvedb not imported'
      1088        evolvedb.args =''



A second problem is, how to make the setup for users (testers) more 
convenient. Is there e.g. any mechanism to apply a patch in an automated 
manner (e.g. using a python library)?



The django commands are hard-coded:

thus elegant/dynamic additions of commands seem not possible.

Another possibility is to enlink (hook?) the functionality into an 
existent function

Is there any way (beside a patch) to alter the behaviour to an existing 
function. Is ther a python construct similar to the "alias_method" of Ruby:

(example from an simple evolution support for a ruby orm)

# use "alias_method" to enlink the code

     class SqliteAdapter
         alias_method :old_create_table,  :create_table
         def create_table(*args)
             result = old_create_table(*args)
             return result


If anyone is interested to verify the results in order to stabelize the 
  simple schema evolution support for django, please review the results 



More information about the Python-list mailing list