Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CONSTRUCT -

1 view
Skip to first unread message

lazaridis_com

unread,
Sep 2, 2006, 12:41:14 PM9/2/06
to
I would like to fulfill the following task:

The construct:

if __name__ == '__main__':

should be changed to something like:

if identifier.name == '__main__':

The term "identifier" should be selected based on the meaning of the
__double-underscore-enclosure__ of the entities.

-

What I would need to know is:

a) what would be the correct term for "identifier"?

b) is there a standard way to implement such an access mechanism in an
generic way?

c) is there an advanced mechanism available, which would allow to
implement a prefix (e.g. %name)

-

Context:
http://case.lazaridis.com/wiki/Lang
http://case.lazaridis.com/ticket/6

Simon Forman

unread,
Sep 2, 2006, 7:49:16 PM9/2/06
to

I'm sorry, you post makes very little sense. If all you want to do is
implement a less "ugly" verision of "if __name__ == '__main__':", a
quick search on google should turn up several ways.

Peace,
~Simon

Georg Brandl

unread,
Sep 3, 2006, 4:02:53 AM9/3/06
to
lazaridis_com wrote:
> I would like to fulfill the following task:
>
> The construct:
>
> if __name__ == '__main__':
>
> should be changed to something like:
>
> if identifier.name == '__main__':
>
> The term "identifier" should be selected based on the meaning of the
> __double-underscore-enclosure__ of the entities.
>
> -
>
> What I would need to know is:
>
> a) what would be the correct term for "identifier"?

import sys
class _identifier:
def __getattr__(self, name):
return sys._getframe(1).f_globals['__%s__' % name]
identifier = _identifier()

Georg

Fredrik Lundh

unread,
Sep 3, 2006, 6:26:46 AM9/3/06
to pytho...@python.org
Simon Forman wrote:

> I'm sorry, your post makes very little sense.

you're somewhat new here, right ? ;-)

</F>

lazaridis_com

unread,
Sep 3, 2006, 12:06:21 PM9/3/06
to
Georg Brandl wrote:
> lazaridis_com wrote:
> > I would like to fulfill the following task:
> >
> > The construct:
> >
> > if __name__ == '__main__':
> >
> > should be changed to something like:
> >
> > if identifier.name == '__main__':
> >
> > The term "identifier" should be selected based on the meaning of the
> > __double-underscore-enclosure__ of the entities.
...

> import sys
> class _identifier:
> def __getattr__(self, name):
> return sys._getframe(1).f_globals['__%s__' % name]
> identifier = _identifier()

ok, I understand.

this one would work with modules.

but how would look a more general solution, which would work with
objects too?

.

--
http://lazaridis.com

lazaridis_com

unread,
Sep 3, 2006, 6:16:49 PM9/3/06
to

Simon Forman wrote:
> lazaridis_com wrote:
> > I would like to fulfill the following task:
> >
> > The construct:
> >
> > if __name__ == '__main__':
> >
> > should be changed to something like:
> >
> > if identifier.name == '__main__':
...

> > Context:
> > http://case.lazaridis.com/wiki/Lang
> > http://case.lazaridis.com/ticket/6
>
> I'm sorry, you post makes very little sense. If all you want to do is
> implement a less "ugly" verision of "if __name__ == '__main__':", a
> quick search on google should turn up several ways.

this happend already within another thread/ticket:

http://case.lazaridis.com/changeset/45

this here is aboute the underscores in "__name__".

-

search engines are full of information, but when looking for standard
constructs and ways to do something, I rely on feedback from domain
experts.

some search-engine hits:

http://aspn.activestate.com/ASPN/Mail/Message/python-list/830424
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496930
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496920

Georg Brandl

unread,
Sep 4, 2006, 4:53:58 AM9/4/06
to

Why can't you try to come up with something yourself? You should have
had enough exposure to the Python language by now.

Georg

lazaridis_com

unread,
Sep 5, 2006, 9:14:14 AM9/5/06
to

I am not a (python) domain expert.

Thus I am asking here for available standard-solutions, before I
implement an own solution.

Steve Holden

unread,
Sep 5, 2006, 9:39:06 AM9/5/06
to pytho...@python.org
There is no standard solution for the problem you mention.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Simon Forman

unread,
Sep 5, 2006, 11:54:29 PM9/5/06
to


Yah, I've been posting here about three months now. Why, did I miss
something? :-)

Peace,
~Simon

Steve Holden

unread,
Sep 6, 2006, 3:34:21 AM9/6/06
to pytho...@python.org
Yes: the previous posts from the same poster. Ilias Lazaridis'
communications can be a little obscure, to say the least, and it's
apparent that his approach to language evaluaation doesn't emphasize
community experience too heavily. Still, it takes all sorts to make a
newsgroup ...

lazaridis_com

unread,
Sep 6, 2006, 8:03:59 AM9/6/06
to
Steve Holden wrote:
> lazaridis_com wrote:
> > Georg Brandl wrote:
> >>lazaridis_com wrote:
> >>>Georg Brandl wrote:
> >>>>lazaridis_com wrote:
> >>>>
> >>>>>I would like to fulfill the following task:
> >>>>>
> >>>>>The construct:
> >>>>>
> >>>>>if __name__ == '__main__':
> >>>>>
> >>>>>should be changed to something like:
> >>>>>
> >>>>>if identifier.name == '__main__':
> >>>>>
> >>>>>The term "identifier" should be selected based on the meaning of the
> >>>>>__double-underscore-enclosure__ of the entities.
> >>>
> >>>>import sys
> >>>>class _identifier:
> >>>> def __getattr__(self, name):
> >>>> return sys._getframe(1).f_globals['__%s__' % name]
> >>>>identifier = _identifier()
> >>>
> >>>ok, I understand.
> >>>
> >>>this one would work with modules.
> >>>
> >>>but how would look a more general solution, which would work with
> >>>objects too?
> >>
> >>Why can't you try to come up with something yourself? You should have
> >>had enough exposure to the Python language by now.
> >
> > I am not a (python) domain expert.
> >
> > Thus I am asking here for available standard-solutions, before I
> > implement an own solution.
> >
> There is no standard solution for the problem you mention.

I see.

Can one point me to the relevant documentation?

Or at least give me the relevant key-words / Search Phrases?

I remember to have located a relevant PEP, but I cannot find it again.

.

Georg Brandl

unread,
Sep 7, 2006, 5:11:08 AM9/7/06
to
Steve Holden wrote:

>> I am not a (python) domain expert.
>>
>> Thus I am asking here for available standard-solutions, before I
>> implement an own solution.
>>
> There is no standard solution for the problem you mention.

Because it's not a problem for most people ;)

Georg

Ilias Lazaridis

unread,
Sep 12, 2006, 8:37:34 PM9/12/06
to
Steve Holden wrote:
> Simon Forman wrote:
> > Fredrik Lundh wrote:
> >>Simon Forman wrote:
> >>
> >>>I'm sorry, your post makes very little sense.
> >>
> >>you're somewhat new here, right ? ;-)
> >>
> >
> > Yah, I've been posting here about three months now. Why, did I miss
> > something? :-)
> >
> Yes: the previous posts from the same poster. Ilias Lazaridis'
> communications can be a little obscure, to say the least, and it's
> apparent that his approach to language evaluaation doesn't emphasize
> community experience too heavily. Still, it takes all sorts to make a
> newsgroup ...

I'm not evaluation python anymore, I've selected it:

http://case.lazaridis.com/wiki/Lang

At this point, I just try to make it fit my personal requirements:

http://case.lazaridis.com/ticket/6

As a flexible dynamic language, python should allow me to change it a
little.

but, as said:

"
What I would need to know is:

a) what would be the correct term for "identifier"?

b) is there a standard way to implement such an access mechanism in an
generic way?

c) is there an advanced mechanism available, which would allow to
implement a prefix (e.g. %name)
"

You've anwered question b).

Additionally, I had read an PEP which referenced this case, but cannot
find it again. It would be nice to have some answers to the topic, thus
this thread has at least some value for people finding it in archives
(those which agree with me that __name__ has a low readability).

.

0 new messages