3

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?

1
  • 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. Commented Nov 29, 2021 at 17:52

2 Answers 2

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.

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.