Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

__init.py__ is not recognized in module [SOLVED]

EDIT:

I’m an idiot ant the file is called __init__.py and not __init.py__

Thx for the fast replies.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am trying to understand python packages, to eventually generate my own packages.

I read some tutorial and try to code some examples, but I am not stuck with some understanding of the init.py file.

I try to follow this tutorial,
https://timothybramlett.com/How_to_create_a_Python_Package_with___init__py.html

but I get the following error at example3.py

AttributeError: module 'string_func' has no attribute 'stringLength'

This is the tree of files:

.
├── example2.py
├── example3.py
└── string_func
    ├── __init.py__
    ├── stringLength.py
    ├── stringToLower.py
    └── stringToUpper.py

and here the init file

$ cat string_func/__init.py__
from .stringLength import stringLength
from .stringToLower import stringToLower
from .stringToUpper import stringToUpper

and the two shortened examples:
example2:

import string_func.stringLength
some_string = "Hello, Universe!"
print(string_func.stringLength.stringLength(some_string))

Returns 16 as expected.

And example3:

import string_func
some_string = "Hello, Universe!"
print(string_func.stringLength(some_string))

I am using

python3 --version
Python 3.9.9

But got the same error on a python 3.6.x

It feels like the init file is ignored, but I cannot understand why.

I also try to find threads, which already described the issue, but I failed. So if you have any good ressources to better understand module making, I’ll be happy 🙂

Best
christian

>Solution :

it should be

__init__.py

not

__init.py__
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading