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, but it can also execute initialization code for the package or set the __all__
variable, described later.
要创建python包,必须创建__init__.py,只要文件夹下面有这个文件,哪怕是一个空文件,python就认为这是一个包,而不是文件夹。
引用自: An Introduction to Python