On 23 Jan 2006 04:00:40 -0800, Fuzzyman [EMAIL PROTECTED] wrote:
Bengt Richter wrote:
[...]
It wouldn't be shadowing, but I suppose you could replace sys.stdout with
a custom object whose methods check where they were called from.
Then you could give the object initialization parameters as
Bengt Richter wrote:
[snip..]
The following in the write method of the custom out object works :
sys._getframe(1).f_globals['__name__']
sys.stdout.write is *always* called from at least one frame deep in the
stack - so it works.
Yes, that's about what I had in mind, not being able to
On 20 Jan 2006 07:37:15 -0800, Fuzzyman [EMAIL PROTECTED] wrote:
Hello,
I'm trying to redirect standard out in a single namespace.
I can replace sys.stdout with a custom object - but that affects all
namespaces.
There will be code running simultaneously that could import sys
afterwards - so I
Maybe you can use __name__ to determine which module the print statement is in:class out: def write(s,a): if __name__ ==myModule: mylog.write(a) else:
sys.__stdout__.write(a)sys.stdout = out()
--
http://mail.python.org/mailman/listinfo/python-list
Bengt Richter wrote:
On 20 Jan 2006 07:37:15 -0800, Fuzzyman [EMAIL PROTECTED] wrote:
Hello,
I'm trying to redirect standard out in a single namespace.
I can replace sys.stdout with a custom object - but that affects all
namespaces.
There will be code running simultaneously that
Bengt Richter wrote:
On 20 Jan 2006 07:37:15 -0800, Fuzzyman [EMAIL PROTECTED] wrote:
Hello,
I'm trying to redirect standard out in a single namespace.
I can replace sys.stdout with a custom object - but that affects all
namespaces.
There will be code running simultaneously that
Ido Yehieli wrote:
I'm sorry, but i don't see how this will solve the problem? It is
exactly the same, only now you've replaced everything in sys except
just sys.stdout?
In the solution above (which I haven't had a chance to test) you're
just chaning hte reference to sys to point to a
oh, ok...
I guess people have to learn to use a logger instead of print in
production code...
--
http://mail.python.org/mailman/listinfo/python-list
Hello,
I'm trying to redirect standard out in a single namespace.
I can replace sys.stdout with a custom object - but that affects all
namespaces.
There will be code running simultaneously that could import sys
afterwards - so I don't want to make the change in the sys module.
I have an idea
Fuzzyman wrote:
Is there another way to shadow the sys module from a single namespace ?
I've never actually tried this, but try making a copy of the sys module
then replacing the stdout object with your own object. Then you can
replace sys of the namespace with your custom sys module. I guess
I'm sorry, but i don't see how this will solve the problem? It is
exactly the same, only now you've replaced everything in sys except
just sys.stdout?
At any rate, perhapse the code you will write will be more maintainable
if instead of redirecting sys.stdout for some of the code just use a
11 matches
Mail list logo