[Tutor] passing results between functions

Dave Angel d at davea.name
Wed Apr 25 13:44:20 CEST 2012


On 04/25/2012 05:36 AM, Gerhardus Geldenhuis wrote:
> 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

Do what 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'))
This is a syntax error.  When posting code, please use copy/paste so we
don't have to guess which part is just from your retyping.

> It still wasn't good enough so I modified the function to return data as
> follows:
>
> def myfunction

This is another syntax error.  Where are the parens, the arguments, or
the colon?

> returndata = []
Your email program destroyed the indentation here, or is this just
another retyping error?

> # some code
> ...
>   return ''.join(returndata)
>
> so now I can do myfunction(mysecondfunction(sys.argv[1],'ro'))
> or mysecondfunction(myfunction(sys.argv[1],'ro'))

This won't work either, but guessing what's wrong would require that you
actually post the function prototypes and return values.  I infer that
you return a single string from each function, but the functions take
two parameters.  Incidentally, in case you're planning to use the second
parameter 'ro' as a mode for opening the file, I don't believe that 'o'
is a valid mode value.

> so my question is philosophical. Is that the pythonian way or is there a
> better/easier/more efficient way to pass data?

No clue till you actually post some code.

> 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
>
>

-- 

DaveA



More information about the Tutor mailing list