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
import sys
class _identifier:
def __getattr__(self, name):
return sys._getframe(1).f_globals['__%s__' % name]
identifier = _identifier()
Georg
> I'm sorry, your post makes very little sense.
you're somewhat new here, right ? ;-)
</F>
> 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?
.
> > 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
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.
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
Yah, I've been posting here about three months now. Why, did I miss
something? :-)
Peace,
~Simon
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 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
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).
.