Return to Snippet

Revision: 28993
at July 28, 2010 23:41 by silviud


Updated Code
"""
params is a string of the class that you want

example:

my_class = "do_something"

instance = factory(my_class)

the name module is hard coded ...

"""

def factory(cls_string, *args):
    cls = getattr(module, cls_string)
    return apply(cls, args)

Revision: 28992
at July 18, 2010 11:32 by silviud


Initial Code
"""
params is a string of the class that you want

example:

my_class = "do_something"

instance = factory(my_class)

"""

def factory(cls_string, *args):
    cls = getattr(virt, cls_string)
    return apply(cls, args)

Initial URL


Initial Description


Initial Title
factory design pattern in python

Initial Tags
python, design

Initial Language
Python