I am happy with the first part of my code which displays location events OK.
The second part, which uses the eval() method as well as getattr() to display ephem.Body() fields, seems 'unpythonic' to me, and perhaps a little clunky.
Is there a better way of using getattr() without invoking eval() as well to display the Body() fields ?
import ephem
o = ephem.Observer()
o.lat, o.long = '-38','144'
o.date = ephem.now()
# first part
body = getattr(ephem,'Sun')()
events = ['next_rising','next_transit']
for event in events:
print(event,getattr(o,event)(body))
# second part
body = 'Sun'
altaz = ['alt','az']
for a in altaz:
print(a,eval('getattr(ephem,body)(o).' + a))
Just call
getattr()again.