PythonScriptsPro icon indicating copy to clipboard operation
PythonScriptsPro copied to clipboard

def main()

Open SpaceTeddy opened this issue 1 year ago • 4 comments

Dear AlexxIT, thanks a lot for your nice tool. I use it every day and works really good. After the last update it bring even more compatiblity to my python projects. So -> great! ;)

But may I ask a question about main(). is it possible to do something like this?...

async def main():
   freaky_main_code = 1

if __name__ == "__main__":
    asyncio.run(main())

thanks a lot

SpaceTeddy avatar Feb 03 '24 08:02 SpaceTeddy

I don't understand what you want. asyncio or __name__ == "__main__"

AlexxIT avatar Feb 16 '24 10:02 AlexxIT

Well, basically or usually I use a def main(): for a main loop. This works with or name == "main" if the script is not imported from a module etc. If I would like to use async too, It need a function to load. Therefore async main().

I tied my first example in my comment, but the code was not executed. Therefore my question if this kind of code execution is possible, or if there are limitations.

thx

SpaceTeddy avatar Feb 16 '24 11:02 SpaceTeddy

I think I can set __name__ to "__main__", but don't know if this is good idea.

AlexxIT avatar Feb 16 '24 11:02 AlexxIT

Anyhow, no problem. My scripts are running fine, and if this is possible, then it would be nice. If not, no worries

cu Chris

SpaceTeddy avatar Feb 16 '24 11:02 SpaceTeddy