EDIT:
I’m an idiot ant the file is called __init__.py and not __init.py__
Thx for the fast replies.
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__