[wingide-users] Dunno if you can help me...

Joshua J. Kugler joshua at eeinternet.com
Tue Aug 31 15:04:05 MDT 2010


On Tuesday 31 August 2010, Adrian Graham elucidated thus:
> This is not really a WingIDE question, but I thought I'd ask in case
> the answer is so obvious you can reply in seconds.
>
> I'm trying to create a dynamic record set using Python's class
> facility.  I have created a record class to create an empty record:
>
> class Record:
>     pass
>
> I am then trying to create record #1, #2....
>
> using
>
> for i in range( 0, len (record_set):
>      rec + str(i) = Record()
>      { add class attributes }
>
> It doesn't work.  I've used {string} + str(number) before to create
> files, but is there an easy way to do this in this case?
>
> As I said, it's not a WingIde question, so please feel free to tell
> me to get stuffed if you want.

Better to use a dict

records = {}

for i in range( 0, len (record_set):
     records['rec' + str(i)] = Record()
     # add class attributes

If you want "dynamic" variable names, you can start messing around with 
globals() and the like, but better to use a dict.

j

-- 
Joshua Kugler
Part-Time System Admin/Programmer
http://www.eeinternet.com - Fairbanks, AK
PGP Key: http://pgp.mit.edu/  ID 0x73B13B6A


More information about the wingide-users mailing list