Cargando…

What is __name__ for in Python.

What is the if __name__ condition in Python for? If you've seen __main__ at the end of a Python script and wondered why that is there it is to avoid side effects when importing and allowing you to run the file as a script on the terminal. If you want more details, watch this short video where w...

Descripción completa

Detalles Bibliográficos
Clasificación:Libro Electrónico
Formato: Electrónico Video
Idioma:Inglés
Publicado: [Place of publication not identified] : Pragmatic AI Solutions, [2022]
Edición:[First edition].
Temas:
Acceso en línea:Texto completo (Requiere registro previo con correo institucional)
Descripción
Sumario:What is the if __name__ condition in Python for? If you've seen __main__ at the end of a Python script and wondered why that is there it is to avoid side effects when importing and allowing you to run the file as a script on the terminal. If you want more details, watch this short video where we work with a Python script to find out those side effects and how the Python script can change once the if condition with __name__ is done at the end. Next Steps Now that you know about the conditional at the end, you might want to explore writing Python scripts that use this trick. There are several examples you can follow in these GitHub repositories with argparse, the Click framework and using sys.argv: argparse GitHub repo examples sys.argv GitHub repo examples Build Python applications from scratch.
Descripción Física:1 online resource (1 video file (4 min.)) : sound, color.
Tiempo de Juego:00:04:00