Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; '16,': 0.03; 'skip:[ 20': 0.03; 'context': 0.05; 'function,': 0.07; 'params': 0.07; '"%s"': 0.09; 'accepts': 0.09; 'function:': 0.09; 'sub': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'lambda': 0.16; 'oct': 0.16; 'subprocess': 0.16; 'sure.': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'string': 0.17; 'wrote:': 0.17; 'module,': 0.17; '>>>': 0.18; 'subject:] ': 0.19; 'trying': 0.21; 'import': 0.21; 'received:209.85.216.46': 0.21; 'combination': 0.22; 'cc:2**0': 0.23; "i've": 0.23; 'cc:no real name:2**0': 0.24; 'command': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'lines': 0.28; "d'aprano": 0.29; 'dictionary': 0.29; 'key,': 0.29; 'readline': 0.29; 'steven': 0.29; "i'm": 0.29; 'function': 0.30; 'figure': 0.30; 'more,': 0.32; 'could': 0.32; 'print': 0.32; 'getting': 0.33; '+0200,': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'list': 0.35; 'along': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; "i'll": 0.36; 'skip:p 20': 0.36; 'execute': 0.37; 'uses': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'perform': 0.38; 'some': 0.38; 'list,': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'of:': 0.65; 'dict.': 0.84; 'eventually,': 0.84; 'otten': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=a7srPWF6sDViwkQ8RyKOMzyWCVEjvVmIjZCMRZd/Tp8=; b=lVidf/U4148CugXkYYwIdJ/e7BUp//wW/TKDv4jPJ+EpMC24WvV9nyNNxHNx3dsrUr OSPpeymOQkLUWs/px3/1sRnpIyC90Umu7pCiqxrt3/n+Qof6zFWSFoQqYHdzivX0M9Gz sMCEuv4zYfz9Ked9GIr8bghsDe8KV4Wmlq570PzQv89+j08uyvK/PQ1s+kacF0KygFky UsMEHGuqzUQhG13IWKzLkS73Ws30D4js9C6kS+Y3zr6CMQ3U4//0wcwXBNflRF+8zjxG 6z/L6kYkE2MyiM2PWcql3WVN2uy5QBszrw6SjWxVR6u66giZTcBhqcT+nHWJySX/rGyN 1j+g== MIME-Version: 1.0 In-Reply-To: <507d44a9$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <50796ce5$0$6574$c3e8da3$5496439d@news.astraweb.com> <507d44a9$0$6599$c3e8da3$5496439d@news.astraweb.com> Date: Tue, 16 Oct 2012 10:14:54 -0400 Subject: Re: [on topic] Re: readline trick needed From: Dwight Hutto To: "Steven D'Aprano" Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350396905 news.xs4all.nl 6965 [2001:888:2000:d::a6]:57599 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31406 On Tue, Oct 16, 2012 at 7:27 AM, Steven D'Aprano 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