How can I get the value of a <property object at 0x...> in Python

Sibte Raza picture Sibte Raza · Aug 5, 2014 · Viewed 10.5k times · Source

I am new to Python and using Python 2.7 on Windows I am using Astropy library, but when I want to view an attribute on the following class:

>>> astropy.cosmology.FlatLambdaCDM.Ok0

it returns:

<property object at 0x7fa2c7e206d8>

Same for other attributes on that object. How do I access the numerical values?

Answer

Blckknght picture Blckknght · Aug 5, 2014

I don't know anything about astropy myself, but from your description it soulds like Ok0 is a property of the FlatLambdaCDM class. You're usually not supposed to try to access properties on a class directly, but rather through an instance of the class.

Try something like:

# create an instance
instance = FlatLambdaCDM()  # the constructor may require some arguments

# access the property on the instance
instance.Ok0

I don't know what arguments (if any) the FlatLambdaCDM class constructor requires, so you may need to add some more stuff to get a workable object.