Must use __init__.py to import a pkg?

Discussion in 'App Development' started by deanstreet, Jul 3, 2021.

  1. In Java, we just put a shitload of class files in a folder (package com.exmaple.shitload) and import com.example.shitload.* to import them all.

    In Python, import com.example.shitload or from com.example.shitload import * doesn't work. If there is this __init__.py having __all__ = [shit1, shit2, ..., shit999] inside the shitload folder, then from com.example.shitload import * works, but I have to write a script just to create that __init__.py file.

    Is there any way to make it just work like Java?
     
    Trade Prophet likes this.
  2. The init file can be empty then any import from any file in the shitload directory will just work. You still need to create it but the IDE will usually do it for you

    GAT
     
  3. kmiklas

    kmiklas

  4. carrer

    carrer

    Just create an empty "__init__.py" file in the folder.
     
    Trade Prophet likes this.