Open GoogleCodeExporter opened 9 years ago
[deleted comment]
Ok, nevermind that above, it doesn't work. I wrote better code to be inserted
at the same spot. Now it checks in the parse_map to see if there are the
longitude and latitude attributes that were parsed. If so, it will dynamically
grab the name of the attribute, get the value and create a corresponding
'_decimal' attribute with the calculated value.
#Calculate the decimal value of the longitude and latitude if the attribute is present in the sentence
for attribute in self.parse_map:
if attribute[0].lower() == 'longitude':
#Get the longitude attribute dynamically using the attribute name from parse_map
longitude = getattr(self,attribute[1])
#Add failsafe for empty values from invalid sentences
if longitude != '':
self.longitude_decimal = float(longitude[3:])/60+float(longitude[:3])
#To be consistent, create empty attribute, prevent AttributeError in downstream code
else:
self.longitude_decimal = ''
if attribute[0].lower() == 'latitude':
#Get the latitude attribute dynamically using the attribute name from parse_map
latitude = getattr(self,attribute[1])
#Add failsafe for empty values from invalid sentences
if latitude != '':
self.latitude_decimal = float(latitude[2:])/60+float(latitude[:2])
#To be consistent, create empty attribute, prevent AttributeError in downstream code
else:
self.latitude_decimal = ''
Sorry for the stupid first post.
Charles.
Original comment by charlesf...@gmail.com
on 30 Apr 2013 at 7:56
Original issue reported on code.google.com by
charlesf...@gmail.com
on 30 Apr 2013 at 6:55