Question

I am using pyproj.Geod to calculate geographic distances, and I would like to use the diameter of the earth defined by the object for another calculation.

When there is no __getitem__ attribute and the object is not indexable, is there a way of extracting a value from it?

Calling the object:

import pyproj
g = pyproj.Geod(ellps='WGS84') # Use WGS84 ellipsoid

Trying to call it by parameter name:

print g['a'] # the diameter parameter
TypeError: 'Geod' object has no attribute '__getitem__'

Testing indexing:

print g[0] 
TypeError: 'Geod' object does not support indexing

Update: Calling print dir(g):

print dir(g)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_fwd', '_inv', '_npts', 'a', 'b', 'es', 'f', 'fwd', 'initstring', 'inv', 'npts', 'sphere']
Was it helpful?

Solution

Are you looking for the getattr built-in function?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top