Finding the instance reference of an object

Chuckk Hubbard badmuthahubbard at gmail.com
Mon Oct 27 19:20:56 EDT 2008


I'm sorry to say I'm pretty confused by the example, but if you want
something like

bob = module.object()
frank = module.object()
and then to know that bob is bob from a list of instances, you could
instead do something like:

for person in listofnames:
     temp = module.object(person)
     list.append(temp)

where the __init__ function assigns the argument to object.nametag or
something.  This way you can retrieve the name from an index into the
list, or retrieve the index by searching for the name...
-Chuckk

On Thu, Oct 16, 2008 at 5:04 PM, Astley Le Jasper
<Astley.lejasper at gmail.com> wrote:
> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.badmuthahubbard.com



More information about the Python-list mailing list