[Tutor] Function design

Eduardo Vieira eduardo.susan at gmail.com
Mon Oct 26 20:08:10 CET 2009


Hello, I need your help in designing a function. I have created this
script to check out if certain column in some csv files has value "0":

import csv

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]:
            final.writerow(row)


if __name__ == '__main__':
    zerofound('pricesfrombv.csv', 'noprices_in_BV.csv', 4)
    zerofound('excelbv.csv', 'noprices_in_ExcelBV.csv', 6)

My question is. Is it OK to create functions with no "returns"?
Basically what I did resembles a subroutine, right? How could I
redesign this to use "return"?

Thanks for your input,

Eduardo


More information about the Tutor mailing list