Does This Belong In a Dictionary?

Steve Holden sholden at holdenweb.com
Mon Dec 9 08:28:49 EST 2002


"beno" <zope at thewebsons.com> wrote in message
news:mailman.1039438391.32504.python-list at python.org...
> Hi;
> I'm writing UML for a shopping cart. Some of the methods have huge amounts
> of variables passed back and forth. For example, the following:
>
>
cueForShipment(customerID:int;basketID:int,firstName:string,middleInitial:st
ring,lastName:string,address1:string,address2:string,city:string,state:strin
g,zip:string,shipFirstName='':string,shipLastName='':string,shipaddress1='':
string,shipAddress2='':string,shipCity='':string,shipState='':string,shipZip
='':string,country:string;shipCountry='':string,wrapGift:bool)
>
> Should I simply pack everything but the IDs into a dictionary?
> TIA,
> beno
>
Well you could, but you might find it simpler to create a class whose
attributes are the values you need. Then instead of referring to
myCue["lastName"] you could use myCue.lastName, and so on.

A simple but not sufficiently rigorous example might be:

    class cueForShipment:
        def __init__(**kwds):
            self.__dict__.update(kwds)

but if you look in the Python cookbook (a very valuable resource, by the
way) at

    http://aspn.activestate.com/ASPN/Cookbook/Python/

you'll find more sophisticated ideas based on this concept.

regards
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Previous .sig file retired to                    www.homeforoldsigs.com
-----------------------------------------------------------------------






More information about the Python-list mailing list