return statement in functions
Jp Calderone
exarkun at intarweb.us
Tue Dec 23 11:02:28 EST 2003
On Tue, Dec 23, 2003 at 10:37:47AM -0500, hokieghal99 wrote:
> OK, I took the good advice I was given here and made my functions very
> specific. I made them all return something sane... something one would
> expect them to return. I even wrote a function to handle the report
> writing itself, but when it gets the output from the other functions to
> write the report file, it only writes this:
>
> <function fs_object_count at 0x405d84c4>
> <function clean_dir_names at 0x405d8534>
> <function clean_file_names at 0x405d856c>
> <function clean_dir_spaces at 0x405d85a4>
> <function clean_file_spaces at 0x405d85dc>
> <function doc_extension at 0x405d8614>
> <function xls_extension at 0x405d864c>
> <function pdf_extension at 0x405d8684>
> <function ppt_extension at 0x405d86bc>
> <function wpd_extension at 0x405d86f4>
> <function jpg_extension at 0x405d872c>
>
> I would like for it to write out what the functions returned. Obviously,
> I am missing something very fundamental here. Could someone hit me in
> the head with a hammer and help me understand this?
>
> Here is an example of what I'm trying to do. Please be gentle with me.
> From experience, I know that intelligence and modesty do not mix, but
> make an exception for me, just this once...
>
> The ugly report function:
>
> def report(a,b,c,d,e,f,g,h,i,j,k):
> outputFile = open('report.txt', 'w')
> print >> outputFile, a
> print >> outputFile, b
> print >> outputFile, c
> print >> outputFile, d
> print >> outputFile, e
> print >> outputFile, f
> print >> outputFile, g
> print >> outputFile, h
> print >> outputFile, i
> print >> outputFile, j
> print >> outputFile, k
> outputFile.close()
Ugly *indeed*
def report(*work):
outputFile = open('report.txt', 'w')
for f in work:
outputFile.write(str(work()) + '\n')
outputFile.close()
Notice how it does "work()", not "work". This is the root of the trouble
in your solution - you aren't calling the functions.
Jp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20031223/11750606/attachment.sig>
More information about the Python-list
mailing list