Python iterators can be advanced manually, as well as implicitly. Assuming you'll only be reading a single value, not checking over and over (and don't want to store all values in memory for whatever reason), you could do:
def find_latlong(locname, locfile):
with open(locfile) as f:
for line in f:
if line.rstrip() == locname:
try:
return float(next(f)), float(next(f))
except StopIteration:
break
raise ValueError("location {!r} not found".format(locname))
This just looks for the line matching the provided name in the provided file, and manually iterates to get the next two lines when it is found.
An alternative that assumes the exact three line pattern, and doesn't check the non-name lines:
from future_builtins import map, zip # Only on Python 2
def find_latlong(locname, locfile):
with open(locfile) as f:
f = map(str.rstrip, f)
for header, lat, lng in zip(f, f, f): # Reads three lines at a time
if header == locname:
return float(lat), float(lng)
raise ValueError("location {!r} not found".format(locname))