2

I am working on a python project that doesn't have too much cross use of functions in different files. I also don't have cases where a file is needing to use something in a different folder than the one it is in.

Is it bad practise for me not to have any __init__.py files in the project at the moment. I don't fully understand the benefit of adding them in?

Daniel Wyatt
  • 960
  • 1
  • 10
  • 29
  • 1
    If you need them, you _need_ them -- you can't `import` your code without them. If everything works as-is without them, then you don't need them. It's not a "is this good practice?" thing, it's a "what do you need to do to to make your code work at all?" thing. – Charles Duffy Nov 29 '21 at 17:52

2 Answers2

2

An __init__.py file makes Python treat a folder as a module, so you can import foldername. It is commonly used for large modules.

If you're not doing that, you don't need an __init__.py file.

kindall
  • 178,883
  • 35
  • 278
  • 309
0

From the docs: "The init.py files are required to make Python treat directories containing the file as packages. This prevents directories with a common name, such as string , unintentionally hiding valid modules that occur later on the module search path."

So you need it to import scripts.

ChinDaMay
  • 204
  • 1
  • 11