Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly write a module?

I have the following directory structure

enter image description here

RawRepo contains a simple class:

class RawRepo:
    pass

init.py contains:

__all__ = ["RawRepo"]

And yap-analysis.py, my "main file", uses either of the following, but it doesn't work:

from yap import RawRepo
from yap import *

when I try to instantiate it, saying:

TypeError: 'module' object is not callable

How to make it actually work? I want yap to be the module, and RawRepo just one of its classes.


1 Answers

Import the class in yap/init.py:

from .RawRepo import RawRepo

Then you can import it in yap-analysis.py like this:

from yap import RawRepo

Note that you can group multiple classes in on module. You should also consider to rename the module to something like raw_repo to conform to PEP8, "modules should have short, all-lowercase names."

like image 95
Daniel Hepper Avatar answered Nov 22 '25 10:11

Daniel Hepper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!