Re: Redirecting standard out in a single namespace

2006-01-24 Thread Bengt Richter
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

Re: Redirecting standard out in a single namespace

2006-01-24 Thread Fuzzyman
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

Re: Redirecting standard out in a single namespace

2006-01-23 Thread Bengt Richter
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

Re: Redirecting standard out in a single namespace

2006-01-23 Thread Pan Menghan
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

Re: Redirecting standard out in a single namespace

2006-01-23 Thread Fuzzyman
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

Re: Redirecting standard out in a single namespace

2006-01-23 Thread Fuzzyman
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

Re: Redirecting standard out in a single namespace

2006-01-21 Thread Fuzzyman
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

Re: Redirecting standard out in a single namespace

2006-01-21 Thread Ido Yehieli
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

Redirecting standard out in a single namespace

2006-01-20 Thread Fuzzyman
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

Re: Redirecting standard out in a single namespace

2006-01-20 Thread Farshid Lashkari
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

Re: Redirecting standard out in a single namespace

2006-01-20 Thread Ido Yehieli
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