[Tutor] Is there a way to use "with" across suite boundaries?

Mark Lawrence breamoreboy at yahoo.co.uk
Sat May 23 09:02:22 CEST 2015


On 23/05/2015 06:56, Jim Mooney Py3.4.3winXP wrote:
> '''I was using with open...:, but I'm printing a header in one function,
> calling a looping
> function to print detail lines, then returning to the calling function to
> print
> the footer. But that didn't work since the with statement only seems to work
> with the lexical suite and the file wasn't open in the detail print
> function. Is there
> a way around this, other than passing the file as I have here? Also, is it a
> good idea to pass a file handle like that or is there a better way?
>

Will you please be precise about the problems that you have, "that 
didn't work" is usually less than useless.  However on this occasion it 
seems that all you have to do is pass the file handle, it's a standard 
way of doing things.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list