473,549 Members | 3,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,arg 1,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 1613
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,arg 1,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
3099
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 text out of dynamically built control. I tried to put my table between div and read div.innerHTML then - HTTP exception has been thrown. Any thoughts,...
0
1596
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 than 16MB then the VB app fails ("Run-time error '91': Object variable or With block variable not set" - break occurs on line "Print #hFile,...
1
2088
by: William | last post by:
Looking for a pre built dotnet corporate or small business website template.
0
1431
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 time) so that they could be used on the .NET platform. I would like to be able to do both explicit and implicit linking. Could anyone please tell...
3
1254
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 .NET FW 1.1 so we want to make sure all of our stuff uses the .NET FW 1.0. We read some tech articles that say this is possible. ...
0
1121
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 specifications including registration, my account, purchase history among other menus up to 11. how do create an interface where you can view and...
7
1504
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? Sincerely Yours, pujo
48
4898
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 David Daniels where he said that probably the VS2003 toolkit will be used for Python 2.5 again. However, even before the release of Python 2.5, I...
3
1770
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 them each night based on a list of active customers. I need to be able to stop the first service before starting the second service and then when the...
2
1862
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 has postgres database access statement it gives me following error : "Can't locate object method "connect" via package "DBI" (perhaps you forgot...
0
7518
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7715
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.