cmd with three arguments
Tim Chase
python.list at tim.thechases.com
Mon May 17 09:12:39 EDT 2010
On 05/17/2010 07:11 AM, kaklis at gmail.com wrote:
> While playing with the Python Standard Library, i came across "cmd".
> So I'm trying to make a console application. Everything works fine, i
> created many function with do_....(self, line) prefix, but when i
> tried to create a function with more arguments
> i can't make it work. e.g
> def do_connect(self, ip, command):
>
>>>> connect 127.0.0.1 delete
> Are there any work arounds
You simply receive all the text after the command:
class C(Cmd):
def do_thing(self, arguments):
print repr(arguments)
If you want to split it, you can do it boringly:
def do_thing(self, arguments):
args = arguments.split()
or you can let Python's standard library do some heavy-lifting
for you:
import shlex
#...
def do_thing(self, arguments):
args = shlex.split(arguments)
-tkc
More information about the Python-list
mailing list