Based on the answers to this question, the pass
keyword in Python does absolutely nothing. It simply indicates that "nothing will be done here."
Given this, I don't understand the use of it. For example, I'm looking at the following block of code while trying to debug a script someone else wrote:
def dcCount(server):
ssh_cmd='ssh user@subserver.st%s' % (server)
cmd='%s "%s"' % (ssh_cmd, sub_cmd)
output=Popen (cmd, shell=True, stdout=PIPE)
result=output.wait()
queryResult=""
if result == 0:
queryResult = output.communicate()[0].strip()
else:
pass
takeData(server, "DC", queryResult)
Is there any purpose at all to having else: pass
here? Does this in any way change the way the function runs? It seems like this if
/else
block could be rewritten like the following with absolutely no change:
if result == 0:
queryResult = output.communicate()[0].strip()
takeData(server, "DC", queryResult)
... or am I missing something? And, if I'm not missing something, why would I ever want to use the pass
keyword at all?