Listing object’s member variables in python

Today, I struggled trying to access amember variable of ASE‘s Atoms instance but I don’t know exactly the variable name. Printing out instance show some data but not what I need: >>>print(centerImage) Atoms(symbols=’OH2′, positions=…, cell=[15.0, 15.0, 15.0], pbc=[True, True, True], calculator=SinglePointCalculator(…)) This can be easily found using the following statement: [instance].__dict__.keys() __dict__.keys() is a python built-in feature to list instance/object’s member variable. Here is the result: >>>print(centerImage.__dict__.keys()) [‘info’, ‘adsorbate_info’, ‘_celldisp’, ‘_calc’, ‘arrays’, ‘_pbc’, ‘_cell’, ‘_constraints’] And thus, all the member variables of an object is shown! Advertisements Continue reading Listing object’s member variables in python