Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > readline trick needed

Reply
Thread Tools

readline trick needed

 
 
Steven D'Aprano
Guest
Posts: n/a
 
      10-13-2012
I'm working with the readline module, and I'm trying to set a key
combination to process the current command line by calling a known
function, *and* enter the command line.

Something along the lines of:

* execute function spam() in some context where it can access
the current command line as a string
* enter the command line

Function spam() may or may not modify the command line.

Here is what I have got so far: I can discard the current line and call a
function:

readline.parse_and_bind(r'"\C-p": "%cspam()\n"' % 0x15) # ^U

binds ctrl-P to the key combinations `ctrl-U spam() Enter`, which clears
the command line before entering spam().

If I leave out the ctrl-U, I'll get a SyntaxError or other exception,
e.g. command line `x = 123` gets transformed into `x = 123spam()`.


This is not suitable:

readline.parse_and_bind(r'"\C-p": "; spam()\n"')

because it changes the command line. It's okay for spam() itself to
modify the command line, but the key binding should not.

I tried to do this:

readline.parse_and_bind(r'"\C-p": "\nspam()\n"')

but it gives me a segmentation fault, which is a little less helpful than
I had expected.

This Stackoverflow question suggests that what I want is not possible in
vanilla Python:

http://stackoverflow.com/questions/11680356


but I'm a stubborn guy and I have not given up yet. Any suggestions?


(P.S. I'm aware of IPython, I want to get this working in the standard
CPython interpreter.)


--
Steven
 
Reply With Quote
 
 
 
 
Etienne Robillard
Guest
Posts: n/a
 
      10-13-2012
On 13 Oct 2012 13:30:14 GMT
Steven D'Aprano <(E-Mail Removed)> wrote:

> I'm working with the readline module, and I'm trying to set a key
> combination to process the current command line by calling a known
> function, *and* enter the command line.
>
> Something along the lines of:
>
> * execute function spam() in some context where it can access
> the current command line as a string
> * enter the command line
>
> Function spam() may or may not modify the command line.
>
> Here is what I have got so far: I can discard the current line and call a
> function:
>
> readline.parse_and_bind(r'"\C-p": "%cspam()\n"' % 0x15) # ^U
>
> binds ctrl-P to the key combinations `ctrl-U spam() Enter`, which clears
> the command line before entering spam().
>
> If I leave out the ctrl-U, I'll get a SyntaxError or other exception,
> e.g. command line `x = 123` gets transformed into `x = 123spam()`.
>
>
> This is not suitable:
>
> readline.parse_and_bind(r'"\C-p": "; spam()\n"')
>
> because it changes the command line. It's okay for spam() itself to
> modify the command line, but the key binding should not.
>
> I tried to do this:
>
> readline.parse_and_bind(r'"\C-p": "\nspam()\n"')
>
> but it gives me a segmentation fault, which is a little less helpful than
> I had expected.
>
> This Stackoverflow question suggests that what I want is not possible in
> vanilla Python:
>
> http://stackoverflow.com/questions/11680356
>
>
> but I'm a stubborn guy and I have not given up yet. Any suggestions?
>
>
> (P.S. I'm aware of IPython, I want to get this working in the standard
> CPython interpreter.)
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list



Why dont you grow yourself some usable neurons instead ? Don't you realize now stackoverflow.com is starting
to hurt your capacity to cogitate on your own or have you not realized this yet?

Cheers,

Etienne


--
Etienne Robillard
Green Tea Hackers Club
Fine Software Carpentry For The Rest Of Us!
http://gthc.org/
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      10-13-2012
On Sun, Oct 14, 2012 at 12:44 AM, Etienne Robillard
<(E-Mail Removed)> wrote:
> Why dont you grow yourself some usable neurons instead ? Don't you realize now stackoverflow.com is starting
> to hurt your capacity to cogitate on your own or have you not realized this yet?


Excuse me?

I'm not overly familiar with readline, so perhaps there is a really
obvious way to do what Steven's trying to do, but this post does not
appear to be the result of a lack of thinking.

If it really IS that obvious to you, post a link to appropriate
documentation without the rudeness... that way it'll be useful to
everyone, not just cathartic to you.

ChrisA
 
Reply With Quote
 
Etienne Robillard
Guest
Posts: n/a
 
      10-13-2012
On Sun, 14 Oct 2012 00:47:52 +1100
Chris Angelico <(E-Mail Removed)> wrote:

> Excuse me?
>
> I'm not overly familiar with readline, so perhaps there is a really
> obvious way to do what Steven's trying to do, but this post does not
> appear to be the result of a lack of thinking.
>
> If it really IS that obvious to you, post a link to appropriate
> documentation without the rudeness... that way it'll be useful to
> everyone, not just cathartic to you.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list


whatever. i don't feel much like replying to idiots today so your apologies
and useless if not irrelevant.



--
Etienne Robillard
Green Tea Hackers Club
Fine Software Carpentry For The Rest Of Us!
http://gthc.org/
(E-Mail Removed)
 
Reply With Quote
 
Roel Schroeven
Guest
Posts: n/a
 
      10-13-2012
Etienne Robillard schreef:
> On Sun, 14 Oct 2012 00:47:52 +1100
> Chris Angelico <(E-Mail Removed)> wrote:
>
>> Excuse me?
>>
>> I'm not overly familiar with readline, so perhaps there is a really
>> obvious way to do what Steven's trying to do, but this post does not
>> appear to be the result of a lack of thinking.
>>
>> If it really IS that obvious to you, post a link to appropriate
>> documentation without the rudeness... that way it'll be useful to
>> everyone, not just cathartic to you.
>>
>> ChrisA
>> --
>> http://mail.python.org/mailman/listinfo/python-list

>
> whatever. i don't feel much like replying to idiots today


Then simply don't. Much better then replying in such a rude way.

I leave the question of who is being an idiot here as an exercise to the
reader.

--
"Too often we hold fast to the cliches of our forebears. We subject all
facts to a prefabricated set of interpretations. Too often we enjoy the
comfort of opinion without the discomfort of thought."
-- John F Kennedy

(E-Mail Removed)

 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      10-13-2012
On Sun, Oct 14, 2012 at 8:31 AM, Joshua Landau
<(E-Mail Removed)> wrote:
> With two irritants (including 8888, is it not advisable that python-list
> gets an admin to block these accounts? Even if it does nothing more than
> slow them, that's something.


That's what killfiles are for. You have two options:

http://en.wikipedia.org/wiki/Kill_file
http://bofh.ch/bofh/bsmh2.html

The first option is not perfect, as you'll still see replies that
quote such people's posts. The second has a few issues with local law
enforcement, but other than that, is a very effective means of
avoiding seeing their posts.

ChrisA
 
Reply With Quote
 
Mark Lawrence
Guest
Posts: n/a
 
      10-13-2012
On 13/10/2012 22:31, Joshua Landau wrote:
>
> With two irritants (including 8888, is it not advisable that python-list
> gets an admin to block these accounts? Even if it does nothing more than
> slow them, that's something.
>


Most irritants are mere amateurs compared to Ilias Lazaridis. I wonder
if he's *STILL* researching?

--
Cheers.

Mark Lawrence.

 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      10-13-2012
On Sun, Oct 14, 2012 at 9:25 AM, Joshua Landau
<(E-Mail Removed)> wrote:
> On 13 October 2012 22:44, Chris Angelico <(E-Mail Removed)> wrote:
>>
>> On Sun, Oct 14, 2012 at 8:31 AM, Joshua Landau
>> <(E-Mail Removed)> wrote:
>> > With two irritants (including 8888, is it not advisable that
>> > python-list
>> > gets an admin to block these accounts? Even if it does nothing more than
>> > slow them, that's something.

>>
>> That's what killfiles are for. You have two options:
>>
>> http://en.wikipedia.org/wiki/Kill_file
>> http://bofh.ch/bofh/bsmh2.html
>>
>> The first option is not perfect, as you'll still see replies that
>> quote such people's posts. The second has a few issues with local law
>> enforcement, but other than that, is a very effective means of
>> avoiding seeing their posts.

>
>
> The first's no good for protecting the newbies though. If troll flames
> newbie, then I want to be able to assure newbie that he's not done anything
> wrong or stupid.
>
> The second is a bit better, definitely, but what I'm wanting is to delegate
> these tasks to python-list's admins. I'm lazy, see.


Agreed, defending newbies is important. But not everyone gets
frustrated at trolls. Those who don't, don't bother to killfile them,
and can respond in defense of the newbies. Also, if two or three
non-trolls respond to the original post, the angry troll is only one
of several, which helps dilute the problem a bit. Still not a
solution, but it helps.

ChrisA
 
Reply With Quote
 
Mark Lawrence
Guest
Posts: n/a
 
      10-13-2012
On 13/10/2012 23:26, Joshua Landau wrote:
> On 13 October 2012 23:13, Mark Lawrence <(E-Mail Removed)> wrote:
>
>> On 13/10/2012 22:31, Joshua Landau wrote:
>>
>>>
>>> With two irritants (including 8888, is it not advisable that python-list
>>> gets an admin to block these accounts? Even if it does nothing more than
>>> slow them, that's something.
>>>
>>>

>> Most irritants are mere amateurs compared to Ilias Lazaridis. I wonder if
>> he's *STILL* researching?

>
>
> My god, he even has an encyclopaedia
> entry<http://www.nationmaster.com/encyclopedia/Ilias-Lazaridis>.
> Is he some kind of deity?
>


Oh no he's far higher up the food chain than that. Here's a starter
https://groups.google.com/forum/?fromgroups=#!search/lazaridis$20banned/comp.lang.ruby/plR34TbM3vc/Ev-Hj5F8oKcJ

--
Cheers.

Mark Lawrence.

 
Reply With Quote
 
Mark Lawrence
Guest
Posts: n/a
 
      10-14-2012
On 13/10/2012 23:52, Mark Lawrence wrote:
> On 13/10/2012 23:26, Joshua Landau wrote:
>> On 13 October 2012 23:13, Mark Lawrence <(E-Mail Removed)> wrote:
>>
>>> On 13/10/2012 22:31, Joshua Landau wrote:
>>>
>>>>
>>>> With two irritants (including 8888, is it not advisable that
>>>> python-list
>>>> gets an admin to block these accounts? Even if it does nothing more
>>>> than
>>>> slow them, that's something.
>>>>
>>>>
>>> Most irritants are mere amateurs compared to Ilias Lazaridis. I
>>> wonder if
>>> he's *STILL* researching?

>>
>>
>> My god, he even has an encyclopaedia
>> entry<http://www.nationmaster.com/encyclopedia/Ilias-Lazaridis>.
>> Is he some kind of deity?
>>

>
> Oh no he's far higher up the food chain than that. Here's a starter
> https://groups.google.com/forum/?fromgroups=#!search/lazaridis$20banned/comp.lang.ruby/plR34TbM3vc/Ev-Hj5F8oKcJ
>
>


Yes a real pro. Trolling will never become an Olympic sport as the
guy's so good nobody can compete with him. (If he was American they'd
still have a World Series though Throw his name plus Eclipse,
Netbeans and banned into your search engine of choice and enjoy, but
beware that to really endulge yourself please stock up on vast
quantities of caffeine and sandwiches first cos you'll need them. For
example this http://web.archiveorange.com/archive...wrYZb0gAgMsPa1
points to this http://www.tfeb.org/lisp/mad-people.html

--
Cheers.

Mark Lawrence.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling python 3.1.2 with local readline fails to get readline - help! gavino Python 4 09-20-2010 05:17 AM
Trick needed - passing a large number of parameters to a class eran C++ 7 07-22-2008 06:34 AM
Getting application ReadLine and Perl debugger ReadLine to cooperate Andrew DeFaria Perl Misc 1 01-30-2008 11:46 PM
Readline::readline() blocking all other threads Jean-Michel Ruby 0 12-22-2007 01:00 AM
Compiling when libedit is in path Is there a trick to compiling Ruby when libedit must exist in the search path? Can you statically link to readline 5.0 in some manner? -- Lon Baker Lon Baker Ruby 1 03-21-2005 08:57 AM



Advertisments