I am relatively new to python. I’m trying to create an iterable list with an object variable as follows:
` my_gps = MicropyGPS()
l1=[['Date and Time','',my_gps.date_string('long')],
['Latitude','',my_gps.latitude_string()],
..... etc
]
for i in range(0, (len(l1))):
text = l1[i][2] # I want 'text' to be set to the current value of
# my_gps.date_string('long'), populated elsewhere in the code
print (text)
`
The idea is that I want to be able to create an arbitrarily long list where I can place all the properties, and then iterate through the list at run time. However when the l1 list is instantiated, the current values of the my_gps attributes are initialized in the l1 list, and the my_gps attribute definitions are overwritten.
I have searched for and tried everything I can think of, e.g. defining the object attribute as a string and trying to convert it into the correct format at runtime, as well as using functions such as getattribute and setattribute, but have not been able to get it to work.
Am I approaching this the wrong way? Appreciate any insights.
Zimboy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.