CONSTRUCT -

L

lazaridis_com

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
 
S

Simon Forman

lazaridis_com said:
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

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
 
G

Georg Brandl

lazaridis_com said:
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
 
L

lazaridis_com

Georg said:
lazaridis_com said:
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?

..
 
L

lazaridis_com

Simon said:
....


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
 
G

Georg Brandl

lazaridis_com said:
Georg said:
lazaridis_com said:
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.

Georg
 
L

lazaridis_com

Georg said:
lazaridis_com said:
Georg said:
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.

Georg

I am not a (python) domain expert.

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

Steve Holden

lazaridis_com said:
Georg said:
lazaridis_com said:
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.

Georg


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.

regards
Steve
 
S

Simon Forman

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

</F>


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

Peace,
~Simon
 
S

Steve Holden

Simon said:
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 ...

regards
Steve
 
L

lazaridis_com

Steve said:
lazaridis_com said:
Georg said:
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.

..
 
I

Ilias Lazaridis

Steve said:
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).

..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top