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

1

9

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?

Ciro answered 5/8, 2014 at 2:33 Comment(1)
possible duplicate of How do Python properties work?Papeete
C
11

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.

Chopfallen answered 5/8, 2014 at 3:33 Comment(1)
That's exactly right. See the intro docs to docs.astropy.org/en/stable/cosmology/index.htmlPapeete

© 2022 - 2024 — McMap. All rights reserved.