Hi all-- Trying to learn Python w/little more than hobbyist (bordering on pro/ am, I guess) Perl as a background.
My problem is, I have a list of departments, in this instance, things like "Cheese", "Bakery", et al. (I work @ a co-op health food store). I've populated a list, 'depts', w/these, so that their indexes match our internal indexing (which skips a few #'s). Now, I'd like to simply generate-- and be able to refer to-- a bunch of other lists-sets (for subdepartments) by iterating through this list, and naming each of these subdepartment lists "categoryx", where x is the index # from the master 'depts' list. And then be able to populate & refer to these lists by accessing their variable-including name. In Perl, it's a fairly trivial matter to use a string variable in naming some other kind of variable-- not sure about Python though. My initial, very weak stab at it (don't laugh!) went something like this: for i in range(len(depts)): if depts[i]: categorylistdeptname = 'category' + str(i) categorylistdeptname = [] Not sure what that wound up doing, but it sure didn't seem to work. I'm mean, it's trivial enough to just set up the lists manually; 'category1 = []', 'category2 = []' -- but then, when I'm cycling through the item file-- which contains one field that's a list of subdepartments for the item, & another field w/the item's dept #, I would like to be able to just append new subdept's into whichever categorylist is indicated by the files department #. Hope that's sorta clear. Maybe I'm just SOL, but I thought I'd try asking around before I go crawling back to Perl w/my tail tucked between my legs.... -- http://mail.python.org/mailman/listinfo/python-list