Replacing 'if __name__ == __main__' with decorator (was: Double underscores -- ugly?)
castironpi at gmail.com
castironpi at gmail.com
Sat Feb 23 15:32:59 EST 2008
> @mainmethod
> def main(...)
>
> and like this:
>
> @mainmethod(parser=myparser)
> def main(...)
>
> then you cannot use that decorator for a function that expects or
> allows a function as its first argument? Because how and
If it's called with only one non-keyword parameter, then the language
might have done it; if not, guaranteed not. (More succintly, if it's
not, the language didn't.)
So, to get:
> @mainmethod
> def main(...)
you'll have to check the parameter counts, and you can never invoke
with just one callable parameter, pretty easy; bulky; your choice
between:
@mainmethod()
def main(...)
Note: 'Non-keyword' -and- callable!
More information about the Python-list
mailing list