473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using the built-in cmd class

Has any one got experience in using the built-in cmd class? I have derived a subclass from the base class, but it seems as if the arguments of functions using the cmd-interpreter are limited in their number. Precisely' I have something like this:
..
..def help_add(self):
print "Adds arguments"

def do_add(self,arg1,arg2):
return (arg1 + arg2)

Python complains about the number of arguments in the do_add function. Has anyone got a modified cmd that can handle multiple arguments?

Ashu

Jul 18 '05 #1
1 1611
Dipl. -Ing. Ashu Akoachere wrote:
Has any one got experience in using the built-in cmd class? I have
derived a subclass from the base class, but it seems as if the
arguments of functions using the cmd-interpreter are limited in their
number. Precisely' I have something like this:
.
.def help_add(self):
print "Adds arguments"

def do_add(self,arg1,arg2):
return (arg1 + arg2)

Python complains about the number of arguments in the do_add
function. Has anyone got a modified cmd that can handle multiple
arguments?


The do_* methods get a string consisting of the remainder of the command
line.
So your method has to look like this:
def do_add (self, strarg):
intargs = [int (arg) for arg in strarg.split ()]
print intargs [0] + intargs [1]

If you return something true from a do_* method, the command loop will stop,
this is probably not what you intended.

You can do the split outside of all your do_* methods. This could be done by
overriding the method parseline:
def parseline (self, line):
cmd, arg, line = Cmd.parseline (self, line)
return cmd, arg.split (), line

But if you really want to define the number of arguments in your do_add,
then typing 'add 1 2 3' would lead to a TypeError exception, which is
probably not helpful for the user.

Daniel

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alex Elbert | last post by:
Hi I have built dynamic HTMLTable. Now I want to attach it directly to the Email Body - it is already built, so why not to use a ready table. However, I cannot find the way of getting plain HTML...
0
by: Eric | last post by:
I built a webservice and it needs to pass large amounts of data (50MB+). I built a VB6 test app that uses soap to call the webservice. When the stream of data getting passed back gets larger...
1
by: William | last post by:
Looking for a pre built dotnet corporate or small business website template.
0
by: anthony Lichnewsky | last post by:
Hi, I have here a huge bunch of cygwin-built dlls using heavily posix api calls, and I wanted to know how to link them to some VC .NET library wrapper (using microsoft C runtime libraries this...
3
by: Kevin Jackson | last post by:
We built a web app using ASP.NET that is built with VS .NET. This targets the .NET framework 1.0. We are switching over to Windows Server 2003. We have found some problems running our app on...
0
by: yenruyee | last post by:
how do you use ASP.NET or JSP and MSSQL to built a c2c ecommerce to launch, sell, etc. Site contains user registration and is search engine, enable including an advanced search. has functionality...
7
by: ajikoe | last post by:
Hello, I have an idea to build python module to speed up python code in some of field where pyrex shines such as numeric, code which needs a lot of looping etc. What do you think? ...
48
by: meyer | last post by:
Hi everyone, which compiler will Python 2.5 on Windows (Intel) be built with? I notice that Python 2.4 apparently has been built with the VS2003 toolkit compiler, and I read a post from Scott...
3
by: drewj840 | last post by:
I built a Windows service that sweeps a set of folders every 60 seconds and puts the files into a SQL Server database. I am creating a second service that will delete this set of folders and recreate...
2
by: jmishra | last post by:
Hi, I am compiling perl 5.8 on i386-linux architecture,every thing went fine and I am able to execute normal perl scripts thorugh this newly built perl. But when I try to execute script which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.