[Tutor] Function design
alan.gauld at btinternet.com
Tue Oct 27 00:23:45 CET 2009
"Eduardo Vieira" <eduardo.susan at gmail.com> wrote
> def zerofound(csvfile, outputfile, lastcolumn ):
> """Finds columns with zero prices. Column have 0 index"""
> final = csv.writer(open(outputfile, 'wb'), dialect='excel')
> reader = csv.reader(open(csvfile, 'rb'), dialect='excel')
> for row in reader:
> if '0' in row[:lastcolumn]:
> My question is. Is it OK to create functions with no "returns"?
Yes, its what some other languages call a procedure.
But in this case its probably not the best route.
> redesign this to use "return"?
You could return the number of rows found, that way
the user could check for non zero to see if its worthwhile
even looking in the output file.
Also I think the name of the function could be changed
since it actually creates a file of rows with zero.
So why not call it write_zero_rows() or somesuch then
the row count as a return value would be even more
Author of the Learn to Program web site
More information about the Tutor