Help please: How to assign an object name at runtime

Dan Sommers me at privacy.net
Wed Jun 29 21:31:06 EDT 2005


On 29 Jun 2005 17:55:44 -0700,
"c0chong at gmail.com" <c0chong at gmail.com> wrote:

> The following is the input line of the file: SoftDict-.csv:
>   ca1017,GRPHScriptSet,ADD/REM,Adobe Acrobat 4.0=2005/06/14

> I expected an instance of Machine() to be created with a name ca1017.

> Instead, an object is assigned to l[0] named:
>    <__main__.Machine instance at 0x01282558>

> -----------------------------
> Here is my code:

[ ... ]

      machines = {}

>     for line in FileList('SoftDict-.csv'): # Treat .csv as a text
>         if len(line)==1: break	# Quit processing; end of file
>         l=line.split(',')# Split the line into constituent parts

Delete this:

>         l[0]=Machine()	# Create a Machine() object named: ca1017

And add this in its place:

          machines[l[0]] = Machine()

This will create a dictionary that maps the string 'ca1017' to a newly
created Machine object.

HTH,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>



More information about the Python-list mailing list