insert data in python script

Michael Torrie torriem at gmail.com
Tue Feb 18 09:53:59 EST 2020


On 2/18/20 2:41 AM, alberto wrote:
> Il giorno martedì 18 febbraio 2020 09:34:51 UTC+1, DL Neil ha scritto:
>> 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)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
He explicitly told you what to do.

The problem was "Molecule" is part of the "preos" module, so you have to
refer to it by the module name first.

>> 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
> 
> hi
> honestly i don't understand what i have to do.
> I have been using python for too little time.
> could you help me understand

Did you read everything DL Neil said?  He told you what to do, including
giving you the line of code you need to replace, but also explained why.
 I don't know how one could make it more clear than what he said.

Spend some time to really try to understand what DL Neil is saying.
this is essential Python knowledge he's trying to impart.  Learning to
work with modules and namespaces in Python is pretty much required when
learning and using Python.


More information about the Python-list mailing list