@kvorobiev answered the question of how to extract from a string representation of your data. But the other half of your question was the error:
'ephem.Date' object has no attribute '__getitem__'
According to the PyEphem documentation for the next_rising()
function,
If the search is successful, returns a Date value.
Furthermore, Date
objects have an important property:
Dates are stored and returned as floats. Only when printed, passed to str(), or formatted with '%s' does a date express itself as a string giving the calendar day and time.
When you gave the command risehr = r1[10:12]
, the Python interpreter attempted to get call Date.getattr() to get the fields from a Date object corresponding to the slice 10:12
. Without that method, slicing has no meaning to a Date object.
But all is not lost! You can still get the Date
object's time information:
Call .tuple() to split a date into its year, month, day, hour, minute, and second.
You can then slice this tuple as needed to get the hour:
hour = r1.tuple()[3]
Or exhaustively:
year, month, day, hour, minute, second = r1.tuple()