Where to insert Python readline?
Gary Bishop
gb at cs.unc.edu
Sun May 18 14:54:05 EDT 2003
I'd like to implement a GNU Readline work-a-like in Python. I'm
encouraged by how easy it was to convert Fredrik Lundh's "Console"
extension to Python using ctypes (great stuff!).
Suppose I implement a Python function that works somewhat like GNU
Readline. My question is, how/where should I inject it into the
existing system to get the effect of using GNU Readline as it works
now?
It seems to me there are several possibilities:
1) I could replace __builtins__.raw_input. That would be really
easy. Would that cover all the cases? I don't think so. It looks to me
like the C code makes direct calls to PyOS_Readline in several
places. What would I miss with this approach?
2) I could use code.interact and pass in my function. This would get
me a command prompt that uses my function. Would that cover all
the cases? Seems it would handle the command prompt nicely but I don't
know if it would handle various calls to input.
3) I could make a C-callable wrapper function (still within ctypes!)
and put a pointer to it in PyOS_ReadlineFunctionPointer. This would
be a bit strange but it should work.
Are these all the choices? Which is "best"?
Thanks
gb
More information about the Python-list
mailing list