Не знаю правильно ли сформулировал вопрос, но все же... У меня есть функция, в которой опредяется 4 переменные путем ввода пользователем, find(lat, lon, pod_str, city):
Где lat, lon - float. И есть функция поиска по ним...
def search(lat = None, lon = None, pod_str = None, city = None):
"""You search by latitude and longitude"""
if lat and lon and pod_str is None and city is None:
list1 = []
for line in file_airport.readlines():
Str_file = ''.join(line)#.title()
List_file = Str_file.split(',')
list1.append(List_file)
if not line:
break
file_airport.seek(0)
for item in list1:
item.append(sqrt((float(item[11]) - float(lat))**2 + (float(item[12]) - float(lon))**2))
list2 = sorted(list1, key = lambda x: x[-1], reverse = False)
list_new = []
x = 10
for item in list2:
while x > 0:
x -= 1
list_new.append(item)
break
config = yaml.load(open('findairport.conf'))
outs = config['output']
for List_file in list_new:
for out in outs:
out = out % dict(airportcode = str(List_file[0]).upper(), distance = List_file[-1], \
airportname = List_file[13], sa = List_file[8], street = List_file[10],\
city = List_file[7], state = str(List_file[5]).upper(), zip = List_file[3], \
country = str(List_file[2]).upper(), lat = str(List_file[11]), lon = str(List_file[12]+'\n'))
print out
file_airport.seek(0)
elif lat is None and lon is None and pod_str or city:
print 'kakawka'
elif lat and lon and pod_str or city:
print 'kakawka'
Почему если я не ввожу lat and lon, программа не заходит в последние 2 условия? Вот условия вызова функции find()
if lat and lon:
search(str(lat),str(lon))
elif pod_str and city:
search(pod_str, city)
elif pod_str:
search(pod_str)
elif city:
search(city)
elif lat and lon and pod_str and city:
search(str(lat),str(lon), pod_str, city)
elif lat and lon and pod_str or city:
search(str(lat),str(lon), pod_str, city)