AlexxIT / PythonScriptsPro

Advanced version of python scripts for Home Assistant without limits
https://github.com/AlexxIT/Blog
117 stars 17 forks source link

def main() #25

Open SpaceTeddy opened 9 months ago

SpaceTeddy commented 9 months ago

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

AlexxIT commented 9 months ago

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

SpaceTeddy commented 9 months ago

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

AlexxIT commented 9 months ago

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

SpaceTeddy commented 9 months ago

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

cu Chris