Fuzzyman wrote: > lazaridis_com wrote: > > I would like to change the construct: > > > > if __name__ == '__main__': > > > > to something like: > > > > if exec.isMain(): > > > > My (OO thought) is to place a class in an separate code module and to > > instantiate an singleton instance which would keep th something like > > this: > > > > class ExecutionEnv: > > def isMain(self) > > if CALLING_MODULE.__name__ == '__main__': > > return true > > else > > return false > > > > exec = ExecutionEnv() > > > > How to I get access to the CALLING_MODULE ? > > sys._getframe(1).f_globals['__name__']
very nice! This seems to do the work. Btw: I forgot to mention the use-case: http://case.lazaridis.com/browser/lang/python/talker.py?rev=44 > All the best, > > Fuzzyman > http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list