[on topic] Re: readline trick needed
Dwight Hutto
dwightdhutto at gmail.com
Tue Oct 16 10:14:54 EDT 2012
More information about the Python-list mailing list
Tue Oct 16 10:14:54 EDT 2012
- Previous message (by thread): [on topic] Re: readline trick needed
- Next message (by thread): [off topic], was Re: [on topic] Re: readline trick needed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Oct 16, 2012 at 7:27 AM, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote: > On Tue, 16 Oct 2012 10:30:01 +0200, Peter Otten wrote: > >> Steven D'Aprano 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 >>> I'm working on the dictionary now,but I came up with this, which uses a list as the key, and accepts the params to perform the function: import subprocess as sub key_list = ['print_something','espeak'] def print_something(params): print "%s" % (params) def espeak(params): sub.call(['espeak','%s' % (params)]) key = raw_input("Please enter key: ") for line in key_list: if str(line) == key: params = raw_input("Enter Params: ") eval("%s('%s')" % (key,params)) I keep getting the function performed in the dict. I'll figure it out eventually, I know I've done it before, and it might be a lambda solution...not sure. But the above could be refined more, it just uses a list, and key/params. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com
- Previous message (by thread): [on topic] Re: readline trick needed
- Next message (by thread): [off topic], was Re: [on topic] Re: readline trick needed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list