我知道我一定错过了一些基本的东西——只是想确保我得到准确的答案。
我有以下代码。为什么在while is notCACHE_KEYS
之后仍然是 None ?load()
CACHE
import bisect
import csv
DB_FILE = "GeoLiteCity-Location.csv"
# ['locId', 'country', 'region', 'city', 'postalCode', 'latitude', 'longitude', 'metroCode', 'areaCode']
CACHE = []
CACHE_KEYS = None
def load():
R = csv.reader(open(DB_FILE))
for line in R:
CACHE.append(line)
# sort by city
CACHE.sort(key=lambda x: x[3])
CACHE_KEYS = [x[3] for x in CACHE]
if __name__ == "__main__":
load()
# test
# print get_geo("Ruther Glen")