Steven D'Aprano wrote:
> Chris Kaynor wrote:
>
>> I was thinking along the lines of replacing:
>>
>> if __name__ == "__main__":
>> <<<block of code>>>
>>
>> with
>>
>> @main
>> def myFunction()
>> <<<<block of code>>
>>
>> Both blocks of code will be called at the same time.
>
>
> You can't guarantee that, because you cannot tell ahead of time when the
> "if __name__" statement will be run. It is *usually* at the end of the
> file, but that's just the normal useful convention, it is not a hard
> requirement.
sure you can: simply the main decorator is just something like
def main(myMainFunction):
if myMainFunction.__module__ == '__main__':
myMainFunction()
return myMainFunction
--
By ZeD
--
https://mail.python.org/mailman/listinfo/python-list