Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59826

Re: Fire Method by predefined string!

Path csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'python,': 0.02; 'else:': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'interpreter': 0.05; 'method.': 0.07; 'sys': 0.07; 'string': 0.09; 'defines': 0.09; 'lawrence': 0.09; 'lines.': 0.09; 'override': 0.09; 'predefined': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'subject:string': 0.09; 'tismer': 0.09; 'runs': 0.10; 'python': 0.11; 'def': 0.12; 'cmd': 0.16; 'converted,': 0.16; 'param': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'language': 0.16; 'wrote:': 0.18; 'implementing': 0.19; 'thanks.': 0.20; 'command': 0.22; '>>>': 0.22; 'programming': 0.22; 'import': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'certainly': 0.24; 'define': 0.26; 'second': 0.26; 'pass': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'on,': 0.29; "i'm": 0.30; "d'aprano": 0.31; 'steven': 0.31; 'class': 0.32; 'another': 0.32; 'but': 0.35; 'add': 0.35; 'building': 0.35; 'possible': 0.36; 'url:org': 0.36; 'turn': 0.37; 'list': 0.37; 'christian': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'commands': 0.60; 'eye': 0.61; 'world.': 0.61; 'our': 0.64; 'fire': 0.65; 'smith': 0.68; 'default': 0.69; 'article': 0.77; '(help': 0.84; 'battery': 0.84; 'person)': 0.84; 'you.)': 0.84; '2013': 0.98
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Fire Method by predefined string!
Date Mon, 18 Nov 2013 02:29:52 +0000
References <mailman.2807.1384725251.18130.python-list@python.org> <roy-53F741.17205217112013@news.panix.com> <5289704c$0$29975$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-78-147-25-45.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0
In-Reply-To <5289704c$0$29975$c3e8da3$5496439d@news.astraweb.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2816.1384741808.18130.python-list@python.org> (permalink)
Lines 55
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1384741808 news.xs4all.nl 15949 [2001:888:2000:d::a6]:44380
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:59826

Show key headers only | View raw


On 18/11/2013 01:41, Steven D'Aprano wrote:
> On Sun, 17 Nov 2013 17:20:52 -0500, Roy Smith wrote:
>
>> In article <mailman.2807.1384725251.18130.python-list@python.org>,
>>   Tamer Higazi <th982a@googlemail.com> wrote:
>
>>> I want the param which is a string to be converted, that I can fire
>>> directly a method. Is it somehow possible in python, instead of writing
>>> if else statements ???!
>>
>> I'm not sure why you'd want to do this, but it's certainly possible
>
> It is very good for implementing the Command Dispatch pattern, which in
> turn is very good for building little command interpreters or mini-
> shells. Python even comes with a battery for that:
>
>
> import cmd
> import sys
> class MyShell(cmd.Cmd):
>      # Override default behaviour of empty lines.
>      def emptyline(self):
>          pass
>      # Define commands for our shell by prefixing them with "do_".
>      def do_hello(self, person):
>          if person:
>              print("Hello, %s!" % person)
>          else:
>              print("Hello!")
>      def do_echo(self, line):
>          print(line)
>      def do_double(self, num):
>          print(2*float(num))
>      def do_bye(self, line):
>          return True
>
> MyShell().cmdloop()
>
>
> This defines and runs a command interpreter that understands commands
> "bye", "double", "echo", "hello" and "help". (Help is predefined for you.)
>
> See also http://drunkenpython.org/dispatcher-pattern-safety.html for
> another use of command dispatch.
>

Neat, and yet another Python site to add to my list to keep an eye on, 
thanks.

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Fire Method by predefined string! Tamer Higazi <th982a@googlemail.com> - 2013-11-17 22:46 +0100
  Re: Fire Method by predefined string! Roy Smith <roy@panix.com> - 2013-11-17 17:20 -0500
    Re: Fire Method by predefined string! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-18 01:41 +0000
      Re: Fire Method by predefined string! Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-18 02:29 +0000
  Re: Fire Method by predefined string! Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-17 14:23 -0800
    Re: Fire Method by predefined string! Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-17 14:38 -0800

csiph-web