This is a python rooky question... The file structure is like that
./part/__init__.py
./part/Part.py
./__init__.py
./testCreation.py
when running python3 testCreation.py I get a
part = Part() TypeError: 'module' object is not callable
no complain about import. so I wonder what the issue is !?
also coming from Java, can some one comment if organising classes for python is better just in packages with subpaths or in modules (ommit the init.py file) ?
1 Answer 1
In Python, you need to distinguish between module names and class names. In your case, you have a module named Part and (presumable) a class named Part within that module. You can now use this class in another module by importing it in two possible ways:
Importing the entire module:
import Part part = Part.Part() # <- The first Part is the module "Part", the second the classImport just the class from that module into your local (module) scope:
from Part import Part part = Part() # <- Here, "Part" refers to the class "Part"
Note that by convention, in Python modules are usually named in lowercase (for instance part), and only classes are named in UpperCamelCase. This is also defined in PEP8, the standardized coding style guide for Python.
Partis a module, not a class.from part.Part import Part, but a minimal reproducible example would help.