CONSTRUCT -

Discussion in 'Python' started by lazaridis_com, Sep 2, 2006.

  1. 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
    lazaridis_com, Sep 2, 2006
    #1
    1. Advertising

  2. lazaridis_com

    Simon Forman Guest

    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
    Simon Forman, Sep 3, 2006
    #2
    1. Advertising

  3. lazaridis_com

    Georg Brandl Guest

    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
    Georg Brandl, Sep 3, 2006
    #3
  4. Simon Forman wrote:

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


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

    </F>
    Fredrik Lundh, Sep 3, 2006
    #4
  5. 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, Sep 3, 2006
    #5
  6. 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
    lazaridis_com, Sep 3, 2006
    #6
  7. lazaridis_com

    Georg Brandl Guest

    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
    Georg Brandl, Sep 4, 2006
    #7
  8. 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.
    lazaridis_com, Sep 5, 2006
    #8
  9. lazaridis_com

    Steve Holden Guest

    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
    Steve Holden, Sep 5, 2006
    #9
  10. lazaridis_com

    Simon Forman Guest

    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
    Simon Forman, Sep 6, 2006
    #10
  11. lazaridis_com

    Steve Holden Guest

    Simon Forman wrote:
    > 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? :)
    >

    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
    --
    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
    Steve Holden, Sep 6, 2006
    #11
  12. 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.

    ..
    lazaridis_com, Sep 6, 2006
    #12
  13. lazaridis_com

    Georg Brandl Guest

    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
    Georg Brandl, Sep 7, 2006
    #13
  14. 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).

    ..
    Ilias Lazaridis, Sep 13, 2006
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Floresita
    Replies:
    3
    Views:
    5,442
    Oggie
    Apr 2, 2004
  2. Kuan Zhou

    Construct synthesis problem

    Kuan Zhou, Apr 22, 2005, in forum: VHDL
    Replies:
    2
    Views:
    511
    Mohammed A khader
    Apr 22, 2005
  3. Alif Wahid

    The 'impure' construct

    Alif Wahid, Jan 4, 2006, in forum: VHDL
    Replies:
    2
    Views:
    8,237
    Reiner Huober
    Jan 4, 2006
  4. Replies:
    2
    Views:
    4,738
    Thomas Stanka
    Mar 27, 2006
  5. Mukesh
    Replies:
    4
    Views:
    605
    Paul N
    Mar 26, 2010
Loading...

Share This Page