...
import preos
# pass name, Tc, Pc, omega
methane = preos.Molecule("methane", -82.59 + 273.15, 45.99, 0.011)
methane.print_params()
...
my code preos in one file preos.py
my commands are
alberto@HENDRIX ~/PREOS $ python3.5
Python 3.5.2 (default, Oct 8 2019, 13:06:37)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
import preos
methane = Molecule("methane", -82.59 + 273.15, 45.99, 0.011)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Molecule' is not defined
The first instruction (immediately above) imports the module preos.py.
That works (no error message!).
The second instruction refers to a Python class called Molecule. That
fails. The error message says that 'Molecule' is not defined.
Yet we can 'see' it. It *has* been defined! What is going on???
In this case, we need to tell Python that Molecule is part of the preos
module. So back to your original code (top):
methane = preos.Molecule("methane", -82.59 + 273.15, 45.99, 0.011)
Please refer to earlier message. If Module were called from code in the
preos.py file, then the "preos." prefix would not be necessary.
The formal term for this situation is "namespaces". Because Molecule is
defined within the preos.py module's namespace we need to tell Python
exactly where Molecule can be found. In the same way that we might say:
if someone in Antarctica wants to see Alberto, (s)he will have to go to
Italy to find him...
Don't hesitate to say if you think my reply is too complicated/advanced.
People here are happy to help...
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list