....if I modify Jonathan's solution to default findAllNames=True,and
Massimo's to return the list (not just the first item)

I see they are not equivalent:

In [13]: getName(f._db)
Out[13]: ['db', '_7', '_10', '_']

In [14]: mName(f._db)
Out[14]: ['__', 'db', '_9', '_7', '_10', '___', 'f', None]

In [15]: mName(db)
Out[15]: ['db', '_9', '_7', '_10', '___', 'f', None]

In [16]: getName(db)
Out[16]: ['db', '_7', '_10']

Ignoring the "None" from Massimo's list (which could be removed), "f"  in
this case is not a desireable part of the result set, as it is not pointing
to the same object referenced by "db" or "_7" (for example).   For that
matter, _9 is not a desirable part of the result set either.

Clearly, these two are not equivalent solutions.

On Wed, Dec 17, 2008 at 10:52 AM, Yarko Tymciurak <yark...@gmail.com> wrote:

> Massimo''s has a small typo:   two paren's after 'return((.....'  and a
> closing paren...
> EIther of these "work" in that they both give me (for example):
>
> getName(db)
> '_5'
>
> getName(f._db)
> '_5'
>
> SO  they are consistent references to some string, presumably with a
> correlation to the SQLStorage object...
>
> with this as my example:
>
>   ydb.define_table('my_table',SQLField('my_field'))
>   f=ydb.my_table.my_field
>
> and using Jonathan's solution, I see this:
>
> In [23]: getName(f._db, findAllNames=True)
> Out[23]: ['_5', 'ydb', '_', '_22']
>
> In [24]: getName(ydb, findAllNames=True)
> Out[24]: ['__', '_5', 'ydb', '_22']
>
>
> As you can see, the variable name you use to reference a given object is
> somewhat arbitrary (it's just a reference), and "the name" (!)  that you
> want is also arbitrary (that is, you could use ydb.my_table  or _5.my_table
> equivalently;  not "_" or "__" as they are transient).
>
> This begs the question:  if you are writing code "live", you can use
> whatever string your heart desires (including picking the first one from
> Jonathan's output that doesn't start with '_').   Actually, maybe that's
> what you really want:  a getName function that returns the first non-'_'
> name.
>
>
>
> So, Denes,  how are you going to use these references to objects?
>
> I guess I'm not understanding something ...
>
> With interest,
> Yarko
>
>
> On Wed, Dec 17, 2008 at 9:58 AM, mdipierro <mdipie...@cs.depaul.edu>wrote:
>
>>
>> Here it is a little shorter
>>
>> def getName(obj): return ([k for k,v in globals().items() if v==obj]+
>> [None])[0]
>>
>> Massimo
>>
>> On Dec 17, 9:33 am, DenesL <denes1...@yahoo.ca> wrote:
>> > Thank you Jonathan, that's exactly it!.
>> > I knew it had to involve globals somehow.
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
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