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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s