Help please: How to assign an object name at runtime

Dan Sommers me at
Thu Jun 30 03:31:06 CEST 2005

On 29 Jun 2005 17:55:44 -0700,
"c0chong at" <c0chong at> 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.


Dan Sommers

More information about the Python-list mailing list