Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > CONSTRUCT -

Reply
Thread Tools

CONSTRUCT -

 
 
lazaridis_com
Guest
Posts: n/a
 
      09-02-2006
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

 
Reply With Quote
 
 
 
 
Simon Forman
Guest
Posts: n/a
 
      09-02-2006
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"?
>
> 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

 
Reply With Quote
 
 
 
 
Georg Brandl
Guest
Posts: n/a
 
      09-03-2006
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
 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      09-03-2006
Simon Forman wrote:

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


you're somewhat new here, right ?

</F>

 
Reply With Quote
 
lazaridis_com
Guest
Posts: n/a
 
      09-03-2006
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

 
Reply With Quote
 
lazaridis_com
Guest
Posts: n/a
 
      09-03-2006

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/Mai...on-list/830424
http://aspn.activestate.com/ASPN/Coo.../Recipe/496930
http://aspn.activestate.com/ASPN/Coo.../Recipe/496920

 
Reply With Quote
 
Georg Brandl
Guest
Posts: n/a
 
      09-04-2006
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.

Georg
 
Reply With Quote
 
lazaridis_com
Guest
Posts: n/a
 
      09-05-2006
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.
>
> Georg


I am not a (python) domain expert.

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

 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      09-05-2006
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.
>>
>>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
--
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

 
Reply With Quote
 
Simon Forman
Guest
Posts: n/a
 
      09-06-2006
Fredrik Lundh wrote:
> Simon Forman wrote:
>
> > I'm sorry, your post makes very little sense.

>
> you're somewhat new here, right ?
>
> </F>



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

Peace,
~Simon

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Behavior of if construct in switch case defualt construct. Mukesh C Programming 4 03-26-2010 12:38 PM
with-select construct question nick.kigs@gmail.com VHDL 2 03-27-2006 11:18 AM
The 'impure' construct Alif Wahid VHDL 2 01-04-2006 07:55 AM
Construct synthesis problem Kuan Zhou VHDL 2 04-22-2005 08:51 AM
VHDL correspondance of Verilog construct Floresita VHDL 3 04-02-2004 01:43 PM



Advertisments