简体   繁体   中英

'Type Error: Nonetype object is not iterable' while comparing lists in Python

I have two functions, Dte() which pulls dates from the database and contains some missing dates and generate_dates() which prints all dates in a range ,I tried to compare both the lists and store zero in place of missing values in a third list( mylist2 ).My code is Below.

def dte(): 
for row in ddt: 
    date = (' '.join(map(str,row))) 
    print(date)      
#dte()

def generate_dates(start_date, end_date):
td = datetime.timedelta(hours=24)
current_date = start_date
while current_date <= end_date:
    print current_date
    current_date += td

start_date = datetime.date(2017, 07, 26)
end_date = datetime.date(2017,9, 11)
#generate_dates(start_date, end_date)


mylist2=[i if i in dte() else 0 for i in generate_dates(start_date, 
end_date)]
print(mylist2)

However when I execute the code, I get an error saying Type Error: Nonetype object is not iterable . What am I doing wrong

You say if i in dte() . This means that you iterate over dte() to see if i is in it. However dte() doesn't return anything, therefore it returns None . So what is actually there is if i in None , and you can't iterate a None .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM