DEV Community

Discussion on: Where should I put this?😕

Collapse
codemouse92 profile image
Jason C. McDonald • Edited

__init__ shouldn't usually contain implementations, so I'd put it in maths.

Then, if you want mylib.maths.is_number to be available as mylib.is_number, you'd put this in __init__.py...

import .maths.is_number as is_number
Enter fullscreen mode Exit fullscreen mode

That will allow you to import it from your library like this:

from mylib import is_number
Enter fullscreen mode Exit fullscreen mode
Collapse
pybash profile image
PyBash Author

Yes, but it is a very common function so, I would want so that it can be imported easily.

Collapse
codemouse92 profile image
Jason C. McDonald

Ergo, the preceding suggestion. You still don't want to put implementation in __init__.py if you can at all help it.

Thread Thread
pybash profile image
PyBash Author

Hmm, I also don't want to, but I want the function to be accessible much easier, you see?

Thread Thread
codemouse92 profile image
Jason C. McDonald • Edited

That's why I suggested what I did. By following the technique I outlined, you can access the function from just mylib instead of mylib.maths. Read my initial comment again carefully.

Thread Thread
pybash profile image
PyBash Author

Yep, your 1st comment explains it... I will try that, it looks good to me. But again, I have to see what others, comment, right?