473,665 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

No tab completion if sys.stdout is redirected

Hi,

I want to have tab completion in my program for interactive input.
Using readline and rlcompleter this works nicely. But I also have to
catch and modify all "print" output, so I redirect sys.stdout
to a custom file-like object. The problem is: After the redirection,
readline support seems suddenly disabled. Why?

Here's an example:

- cut ----
import sys
import rlcompleter
import readline

class DottedWriter(ob ject):
"""Just a simple example for a sys.stdout wrapper"""
def __init__(self, orig_stdout):
self.orig_stdou t = orig_stdout

def write(self, text):
self.orig_stdou t.write("." + text)

readline.parse_ and_bind("tab: complete")
mywriter = DottedWriter(sy s.stdout)

raw_input("Pres s TAB to see that completion works. Then press ENTER:")
print "Replacing sys.stdout with a custom file-like object..."
sys.stdout = mywriter
raw_input("Now tab completion doesn't work anymore. Please try:")
- cut ----

In the first raw_input() call, tab completion works, in the second it
doesn't. Am I doing something wrong here or is it a bug?

Reproduced on Windows (with pyreadline 1.5) and Linux (standard readline
module), both using Python 2.5.1.

Things I have tried without success:
- Simulate all other methods of sys.stdout with __getattr__
def __getattr__(sel f, name): return getattr(self.or ig_stdout, name)
- Use other forms of interactive input
* import code; code.interact()
* input()

Regards
Dirk
Dec 18 '07 #1
3 1867
Dirk Loss wrote:
I want to have tab completion in my program for interactive input.
Using readline and rlcompleter this works nicely. But I also have
to catch and modify all "print" output, so I redirect sys.stdout
to a custom file-like object. The problem is: After the
redirection, readline support seems suddenly disabled. Why?
readline module applies its autocompletion functions to (and only
to) sys.stdout.

Regards,
Björn

--
BOFH excuse #350:

paradigm shift...without a clutch

Dec 18 '07 #2
Bjoern Schliessmann wrote:
readline module applies its autocompletion functions to (and only
to) sys.stdout.
I see. Then I guess I'll have to avoid redirecting sys.stdout and
come up with some kind of workaround instead.
Nevertheless, thanks for the info.

Regards
Dirk
Dec 19 '07 #3
Dirk Loss wrote:
Bjoern Schliessmann wrote:
>readline module applies its autocompletion functions to (and only
to) sys.stdout.

I see. Then I guess I'll have to avoid redirecting sys.stdout and
come up with some kind of workaround instead.
Just use a "central" function for printing output. Inside this
function, you can redirect the output wherever you wish without
touching sys.stdout.

Regards,
Björn

--
BOFH excuse #226:

A star wars satellite accidently blew up the WAN.

Dec 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1922
by: Wes S. | last post by:
How can I redirect and tag sys.stdout values. I tried creating a class module that saved the old stdout and replaced it, but I can't seem to figure out how to do such. Here is what I got... class cStdOutRedirect : stdOld = "" def __main__(self) : stdOld = sys.stdout
0
1184
by: Ahmad Hosseinzadeh | last post by:
Hello, I’m trying to run an external program in my application. Both are coded in python. I need to write an independent module that is used in the main application. Its responsibility is to run the external program and redirect its stdout and stderr to the main application. The application’s stdout and stderr are set to an object and they are not command prompt anymore.
1
5378
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component for this, and a test application for the component. It allows me to specify a command to execute,...
4
6089
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component for this, and a test application for the component. It allows me to specify a command to execute,...
10
21129
by: Michael Gaab | last post by:
If I redirect stdout by using freopen("afile", "w", stdout); and then I closed stdout using, fclose(stdout), essentially I am just closing "afile". I have to reestablish what stdout originally pointed to? thanks
2
5929
by: Thomas W. Brown | last post by:
I have setup Console redirection within my Console app (via Console.SetOut and Console.SetErrror) to route console WriteLine calls to a logfile. This works just fine with one exception... I use PInvoke to call into several unmanaged DLLs which write diagnostic information out to stdout (and possibly stderr). When I run in a "standalone" mode with no redirection, these DLLs do generate output to the console window. But I want to run in...
2
3598
by: Nadav | last post by:
Hi, Introduction: *************** I am trying to redirect stdout to a RichEdit control, this is done by initiating a StringWriter, associated it with a StringBuilder and setting the Console.Out to the String Writer, when ever the RichEdit is to be updated text from the StringBuilder is being copied. The Problem:
9
18282
by: Santtu Nyrhinen | last post by:
Hi, Let say that I have a function like void writeHello() { printf("Hello"); } Now I need to make an automated test fot that function. The test function returns 1 for successful and 0 for unsuccessful test. int Test_writeHello() {
0
2582
by: kreismaler | last post by:
I have some problems to understand the difference of using the STDOUT and using "anonymous pipes" as shown below: using System; using System.Diagnostics; using System.IO; namespace ProcessTest { class Program
0
8438
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8779
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.