473,418 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

curses & disable readline & replace stdin

Hi !

I'd like to init curses and still have working Python interactive
command line. I found that you can replace stdin/stdout/stderr
like this:

#!/usr/bin/python -i

import curses
import sys
import atexit

# this doesn't help, anyway
#del sys.modules['readline']

# global variable (curses window)
stdscr = None

class FakeStdIO(object):

def write(self, str):
global stdscr
stdscr.addstr(str)
stdscr.refresh()

def readline(self):
print "$ ",
return stdscr.getstr()

stdscr = curses.initscr()
atexit.register(curses.endwin)
curses.echo()

f = FakeStdIO()
sys.stdin = f
sys.stdout = f
sys.stderr = f

print 'Hello, curses !' # <-- this works

l = sys.stdin.readline() # <-- this also works fine

# <-- interactive Python prompt doesn't echo imput

It looks that '>>>' prompt is using the readline module, which
is not using sys.stdin at all.

Q: Can you prevent python interpreter to use readline module
(even when it is available), *without* recompiling python ?

I think it should be possible to write a module in C to access
Python internals. But can you do it "from python" ?

The other option is to make readline somehow work with curses.
This is however not what I intended.

Platform: Linux Mandrake, Python 2.3.5

Thanks,

BranoZ

Jul 18 '05 #1
0 2355

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

Similar topics

0
by: J Turner | last post by:
Hello, I'm playing with a python-based shell, which uses (guess what?) python as it's scripting language, for iterative invocation, environment variables, etc. Everything was going well,...
0
by: Stefan Zollinger | last post by:
Hi I'm working on a "telnet" server which should serve piped output from curses based applications. So far it works fine with plain text, but it looks like stdin.readline() scrambles the...
12
by: Mike Maxwell | last post by:
When I invoke readline() in a for loop, why does it return a series of one-char strings, rather than the full line? >>> for sL in sys.stdin.readline(): print sL .... abc a b c
19
by: rbt | last post by:
Here's the scenario: You have many hundred gigabytes of data... possible even a terabyte or two. Within this data, you have private, sensitive information (US social security numbers) about your...
39
by: n00m | last post by:
Given a list of N arbitrarily permutated integers from set {1..N}. Need to find the ordering numbers of each integer in the LONGEST increasing sequence to which this number belongs. Sample: ...
6
by: Christian Convey | last post by:
Hello, I've got a program that (ideally) perpetually monitors sys.stdin for lines of text. As soon as a line comes in, my program takes some action. The problem is, it seems like a very large...
3
by: skip | last post by:
I'm having no success building the curses module on Solaris 8 (yes, I know it's ancient - advancing the state-of-the-art is not yet an option) for Python 2.4. Sun provides an apparently ancient...
0
by: Berend van Berkum | last post by:
Hi all, I'm looking at building an interactive session in front of some rdfobj instances. I've used cmd and just found code.Interactive*. Protocol doesn't matter, I'm looking at the UI...
2
by: Grant Edwards | last post by:
I'm trying to figure out how to use the gnu readline library so that when my program is prompting the user for input there is line editing and history support. I've read and re-read the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.