what is __init__.py please give me example | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is __init__.py please give me example

7th Jan 2019, 12:02 AM
kokito
4 Answers
+ 3
"The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, __init__.py can just be an empty file" https://docs.python.org/3/tutorial/modules.html?highlight=__init__#packages
7th Jan 2019, 12:09 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 3
__init__.py* *__init__.py is a constructror of a package*. *package is a directory of modules*. *module is a file of code. module can be ran from other script as: import module_name *package's certain modules are ran from other script as: import package_name.module_name *package's __init__.py is ran from other scripts as: import package_name
7th Jan 2019, 12:53 AM
Seb TheS
Seb TheS - avatar
7th Jan 2019, 12:11 AM
Ulisses Cruz
Ulisses Cruz - avatar
0
thank
7th Jan 2019, 12:19 PM
kokito