Finding the instance reference of an object

Diez B. Roggisch deets at nospam.web.de
Thu Oct 16 12:53:29 EDT 2008


Astley Le Jasper schrieb:
> On 16 Oct, 16:52, Carsten Haese <carsten.ha... at gmail.com> wrote:
>> Astley Le Jasper wrote:
>>> Sorry for the numpty question ...
>>> How do you find the reference name of an object?
>>> So if i have this
>>> bob = modulename.objectname()
>>> how do i find that the name is 'bob'
>> Why do you need to find that? You know that its name is 'bob'.
>>
>> --
>> Carsten Haesehttp://informixdb.sourceforge.net
> 
> I'm creating mulitple instances, putting them in a list, iterating
> through the list to send them to some functions where process them
> with some instance specific parameters. Something along the lines of:
> 
> bob = someobject()
> harry = someobject()
> fred = someobject()
> 
> parameterdict = {'bob':(0,1,2),'harry':(3,4,5),'fred':(6,7,8)}
> people_list = (bob, harry, fred)
> 
> for person in people_list:
>   add_parameters(person)
> 
> def add_parameters(person)
>   mytuple = parameterdict[??????instance.name????]
>   person.x = mytuple[0]
>   person.y = mytuple[1]
>   person.z = mytuple[2]
> 
> ... alternatively there is probably a very much easier way of doing
> it.

Why not simply do

bob = someobject(0, 1, 2)

?

Diez



More information about the Python-list mailing list