[Tutor] passing results between functions
Gerhardus Geldenhuis
gerhardus.geldenhuis at gmail.com
Wed Apr 25 11:36:16 CEST 2012
Hi
I wrote two functions which does different manipulations on text files.
To start out with I passed the filename as a parameter and each function
opened the file and saved it.
I then realized I would need to do that twice if I wanted to use both my
functions on the same file. I the modified the functions to take the input
as follows:
myfunction(open(sys.argv[1]),'ro'))
It still wasn't good enough so I modified the function to return data as
follows:
def myfunction
returndata = []
# some code
...
return ''.join(returndata)
so now I can do myfunction(mysecondfunction(sys.argv[1],'ro'))
or mysecondfunction(myfunction(sys.argv[1],'ro'))
so my question is philosophical. Is that the pythonian way or is there a
better/easier/more efficient way to pass data?
To be honest I am still a bit stuck in how I did things when I programmed
in Delphi years ago and trying to make the paradigm shift and understanding
the data structures.
Regards
--
Gerhardus Geldenhuis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120425/e9060968/attachment.html>
More information about the Tutor
mailing list