Re: Merge two directories together

2010-04-16 Thread Dave W.
> While Python provides some helpful methods for moving files and > directories around (shutil.move, shutil.copytree, etc), none of > them seem to be able to merge two directories. -snip- > Any ideas? It's not pretty, but you could hack up the original copytree() source so it ignores errors from t

Re: Globally override built-in print function?

2010-04-16 Thread Dave W.
>>> old_print = __builtins__.print >>> __builtins__.print = printhook >>> yield >>> __builtins__.print = old_print > >> I'm pretty sure this is semantically equivalent to my original >> code, but I gave it a try anyway. > > Not at all. Declaring "global print" then assigning to "pri

Re: Suppress output to stdout/stderr in InteractiveInterpreter

2010-04-16 Thread Dave W.
>>> Don't bother. Replacing sys.stdout is the right thing to do. It >>> won't interfere with the C++ streams... >> I'm not so certain. Won't the C++ host app share the same >> stdin/stdout/stderr file descriptors with the embedded Python >> interpreter? > No. Changing the object that the name sys

Re: Suppress output to stdout/stderr in InteractiveInterpreter

2010-04-15 Thread Dave W.
> > Think I'll start a new post with the subject: "Globally override > > built-in print function?" > Don't bother. Replacing sys.stdout is the right thing to do. It > won't interfere with the C++ streams... -snip- I'm not so certain. Won't the C++ host app share the same stdin/stdout/stderr file

Re: Globally override built-in print function?

2010-04-15 Thread Dave W.
> > I naively thought I could capture output from exec()'ed print > > invocations by (somehow) overriding 'print' globally. But this > > seems not to be possible. > >old_print = __builtins__.print >__builtins__.print = printhook >yield >__builtins__.print = old_print I'm pretty

Globally override built-in print function?

2010-04-15 Thread Dave W.
I naively thought I could capture output from exec()'ed print invocations by (somehow) overriding 'print' globally. But this seems not to be possible. Or at least not easy: c:\d>test.py Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] win32 Type "help", "copyright", "

Re: Suppress output to stdout/stderr in InteractiveInterpreter

2010-04-15 Thread Dave W.
> After your reply, I went back and > discovered that everything was actually working fine with 'global' > in place Oops, I lied. It still doesn't work. It doesn't seem possible (or at least not easy) to *globally* override the built-in print function. The best

Re: Suppress output to stdout/stderr in InteractiveInterpreter

2010-04-15 Thread Dave W.
> > I thought I could get away with importing print_function > > from __future__ ... but my re-pointed print function never gets > > called. > -snip- > >def __enter__(self): > >print = self.printhook > That redefines the print function local to __enter__. You need to > change the gl

Suppress output to stdout/stderr in InteractiveInterpreter

2010-04-14 Thread Dave W.
I've subclassed InteractiveInterpreter in an attempt to make it friendlier for use in a remote console for a C++ app. What I really wanted to do was wrap/adapt the base class's runsource() method to return a 2-tuple (more, result) where 'more' is a bool indicating whether a complete command was re