None
should be expr is None
116 # getting a particular sheet by name out of many sheets
117
118 student_batch = request.POST['batch']
119 if student_batch == None:120 student_batch = 2016
121 worksheet = wb["BATCH " + str(student_batch)]
122 print(worksheet)
None
should be expr is not None
129 section = list()
130 instructor = list()
131 for col in worksheet['C']:
132 if(col.value != None):133 code.append(col.value)
134 for col in worksheet['D']:
135 if(col.value != None):
None
should be expr is not None
132 if(col.value != None):
133 code.append(col.value)
134 for col in worksheet['D']:
135 if(col.value != None):136 title.append(col.value)
137 for col in worksheet['E']:
138 if(col.value != None):
None
should be expr is not None
135 if(col.value != None):
136 title.append(col.value)
137 for col in worksheet['E']:
138 if(col.value != None):139 short.append(col.value)
140 for col in worksheet['G']:
141 if(col.value != None):
None
should be expr is not None
138 if(col.value != None):
139 short.append(col.value)
140 for col in worksheet['G']:
141 if(col.value != None):142 crdthr.append(col.value)
143
144 for col in worksheet['I']:
Comparisons to the singleton objects, like True
, False
, and None
, should be done with identity, not equality. Use is
or is not
.
Identity checks are faster than equality checks.
Also, the equality checks can result in unintended behaviour in some cases:
>>> 1 is True
False
>>> 1 == True
True
>>> 1.0 is True
False
>>> 1.0 == True
True
value = fx()
if value == True: # `==` can cause unintended behaviour
print(value)
if value != None:
print(value)
value = fx()
if value is True: # `is` for Identity comparison
print(value)
if value is not None:
print(value)
Equality comparisons might be required in some cases, especially in SQLAlchemy, SQLObject, ORMs, etc. In these cases, it is safe to ignore this issue.