getcat(di) - (line 6) function returns either "None" or some string to my main function.
I would like to add this string in dict if it's not None... Here is code:
getids = Url.objects.values_list('keyword', 'id', 'url')
for keyword, id, url in getids:
if Url.objects.get(id=id).url != None:
...
...
ala = getcat(anResults)
if str(ala) != 'None':
dictt['shopping'] = ala
else:
pass
Problem is that once it passes !='None' it keeps adding that same string to all future loops.
I tried putting break everywhere and can't seem to make it work. If I replace
dictt['shopping'] = ala
with:
print url, ala
it works correctly and prints just the right url and ala value.
Any ideas?
None, useis/is not, not==/!=. e.g. Testif Url.objects.get(id=id).url is not None:.Noneshould almost always be tested using the object identity operators, not rich comparison operators, avoiding overhead and (for poorly written rich comparison operators) exceptions being thrown.