pythonopenbabel

What is a python field relative to other Python-based language constructs?


I'm using the Python OpenBabel package (https://openbabel.org/docs/current/UseTheLibrary/PythonDoc.html) and stepping through my code using the PyCharm IDE. I'm running into a problem, but I must understand the terminology used in PyCharm and the Python Language before I can fix the problem. I'm finding some of the terminology confusing.

This is the code. On the website, this construct works, but when I tried to perform this operation, it doesn't work i.e., the mol instance of class OBMol does not change, even though it returns True (the API docs state that the mol obj changes):

from openbabel import openbabel as ob

pdbqtFile = "a string path to a pdbqt file" 
obConversion = ob.OBConversion()
obConversion.SetInAndOutFormats("pdbqt", "pdb")
mol = ob.OBMol()
obConversion.ReadFile(mol, pdbqtFilePath)

# This is where I'm confused
value = mol.AddHydrogens()

This is where I'm confused:

In the PyCharm drop-down code suggestion, mol.AddHydrogens has a lower-case f next to it. Looking this up, it's called a field. But if I print(mol.AddHydrogens) I get:

<bound method OBMol_AddHydrogens of <openbabel.openbabel.OBMol; proxy of <Swig Object of type 'OpenBabel::OBMol *' at 0x0000022DDB9D5B40> >>

Notice the word method in that output. I understand what that is, but it's been referred to as a field in the IDE. If this is a method, and it states it is, why does PyCharm not have a m in the drop-down suggestions? What is a field, and how does it differ from a method? I have a feeling, the answer will have something to do with this method being bound.


Solution

  • Simple example:

    enter image description here

    shows Foo.derp to be a field (which it is), but the value is definitely callable (since it is just print after all), and print(Foo.derp) will print <built-in function print>.

    You'd need to look at how openbabel is implemented to figure out why PyCharm is showing you a field – but in the grand scheme of things, it doesn't really matter much.