[Python-ideas] Replacing the if __name__ == "__main__" idiom (was Re: making a module callable)
Ron Adam
ron3200 at gmail.com
Mon Nov 25 16:06:47 CET 2013
On 11/24/2013 10:14 PM, Ron Adam wrote:
> Regarding the is_main()... seems like it should take an argument. Most
> is_something() functions do. Is there a way to make something like the
> following work?
>
> def is_main(name=None):
> if name == None:
> name = get_attr_from_caller() # dynamic lookup
> return (name == "__main__")
This should have been...
def is_main(name=None):
if name == None:
name = get_attr_from_caller("__name__") # dynamic lookup
return (name == "__main__")
-Ron
More information about the Python-ideas
mailing list