cmd module

Justin Shaw wyojustin at hotmail.com
Fri Dec 13 23:08:09 EST 2002


"Brian Lee" <senux at senux.com> wrote in message
news:mailman.1039794336.1213.python-list at python.org...
> How can I lower all the characters or how to detect this? I want
> to keep one function as do_FOO(args) while all input foo, Foo, FOO
> can be matched.

Overwrite onecmd.

# junk.py
import cmd
class NoCaseCmd(cmd.Cmd):

    def onecmd(self, line):
        cmd.Cmd.onecmd(self, line.lower())

    def do_foo(self, item):
        '''Works for foo, Foo, and FOO.'''
        print 'foo', item

>>> c = junk.NoCaseCmd()
>>> c.cmdloop()
(Cmd) Foo
foo
(Cmd) FOO
foo
(Cmd) foo junk
foo junk
(Cmd)
Justin





More information about the Python-list mailing list