1

How to dynamically generate methods and properties in Python?

Let's assume that we have a long list and some class:

#!/usr/bin/env python
list = ["sky","sand","sea",...]
class SomeStaticObjClass( object ):    
    def __init__( self, arg, ):    
        # some code

...and want to dynamicaly add names and values to keep the funtionality with code example as follows :

sky = "sky"                                     # generate key and value
sky_OBJECT = SomeStaticObjClass( sky )          # generate name
def sky_Function( arg ): return arg.__class__   # generate function name
print sky_Function( sky_OBJECT )                # proceeding generated object name as argument

...then continue with other list members again... Any help, please?

LuckyLuke
  • 46
  • 4

0 Answers0