Hi Denes -

Thanks for the correction to Massimo's brief snippet;  that seems to correct
the (range of) output.

..."explicit is better..."

However you slice that function it still seems problematic:

In [1]: def getName(obj):
   ...:     return([k for k,v in globals().items() if v is obj]+[None])[0]
   ...:
In [2]: db=SQLDB()

In [3]: db.define_table('ytable',SQLField('yname'))
.....< I'll spare you all the output>.......

In [4]: f=db.ytable.yname

In [5]: getName(db)
Out[5]: 'db'

In [6]: getName(f._db)
Out[6]: '__'

In [7]: def getName(obj):
    return([k for k,v in globals().items() if v is obj]+[None])

In [8]: getName(f._db)
Out[8]: ['db', '_5', '___', None]

In [9]: getName(db)
Out[9]: ['db', '_5', None]

Add another call - say:

In [33]: f._db.ytable.fields
Out[33]: ['id', 'yname']

In [34]: getName(f._db)
Out[34]: ['db', '_5', '_31', '___', None]


- and you create another reference to the object, the order and size of the
list you get back may change ....

Bottom line:      getObjectReferences[0] - however you define it,  does not
appear to be something you can depend on - it may not contain what you want,
or even anything useful.

It seems you need to grab the list, and do something with it to get what you
want.

Regards,
Yarko



On Wed, Dec 17, 2008 at 2:23 PM, DenesL <denes1...@yahoo.ca> wrote:

>
> Hi Yarko,
>
> first there is no typo in Massimo's function.
>
> The problem, as you noted later, is the comparison, it should be: v is
> obj, not v==obj, so the function could be:
> def getNames(obj): return ([k for k,v in globals().items() if v is obj]
> +[None])[0]
> (the [None] is needed so there will not be an IndexError if the list
> is empty).
>
> About how I am going to use this... it is a secret.
> Not!
> I am creating handlers (controller functions) for autocompletes if
> they don't already exist.
> It is part of a patch I am working on, to be submitted for
> consideration later.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to