Global help
Alex Martelli
Alex.Martelli at think3.com
Mon Jan 17 12:09:05 EST 2000
Shaun Allen Dishman writes:
> ----- x.py -----
>
> from y import *
>
> def x(filename):
> file = open(filename, 'w')
> y()
>
> ----------------
>
> ----- y.py -----
>
> def y():
> # must be the same file object as in x.py
> file.write('blah blah blah \n')
>
> ----------------
>
> I have fiddled around with the global settings for the file object but
> cannot seem to get things to work. All I need is to be able to access the
> file object from one module inside of another one, without passing it as a
> parameter. Is this even possible? Thanks in advance.
>
>
It's *possible* -- for example, just change the open to
y.file = open(filename, 'w')
and that, I believe, should "work" -- but I wonder if it's
WISE... you're setting up an extremely strong coupling
between what should be separate modules, by way of
this "shared global variable". Wouldn't a more explicit
approach be preferable?
Alex
More information about the Python-list
mailing list