Generic utility class for passing data

Chris Smith smitty_one_each at bigfoot.com
Sat Oct 29 10:19:24 EDT 2005


>>>>> "Gordon" == Gordon Airporte <JHoover at fbi.gov> writes:

    Gordon> I'm wondering if this is might be bad practice. Sometimes
    Gordon> when I need to pass around several pieces of datum I will
    Gordon> put them in a tuple, then when I need to use them in a
    Gordon> receiving function I get them out with subscripts. The
    Gordon> problem is that the subscript number is completely
    Gordon> meaningless and I have to remember the order I used.  As
    Gordon> an alternative I was considering using a dummy class like
    Gordon> this:

    Gordon> class Dummy: pass

    Gordon> Then when I need to pass some related data, Python lets me
    Gordon> do this:

    Gordon> prefill = Dummy() prefill.foreground = 'blue'
    Gordon> #"foreground" is made up on the fly prefill.background =
    Gordon> 'red' prefill.pattern = mypattern return prefill

    Gordon> Now I can access the data later using meaningful names.
    Gordon> Is this going to cause problems somehow? Should I rather
    Gordon> go to the trouble of creating more substantial individual
    Gordon> classes for every grouping of data I might need to pass
    Gordon> (with __init__'s and default values and so on)? Should I
    Gordon> just stick with subscripted groupings because of the
    Gordon> overhead?

May fortune smile on Zoran Isailovski, whose Enum class is exactly
what you want:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486
-Chris



More information about the Python-list mailing list