Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > sub-shell errors

Reply
Thread Tools

sub-shell errors

 
 
Bigbowser
Guest
Posts: n/a
 
      08-20-2004
Hi all,

I'm trying to create a sub shell environment ( i
haven't really got a reason, its more of a test,
although hopefully it will make life easier ;P )
but whenever i try to call the commands i've created
i get :
[ ice being the sub-shells name ]

ICE> help
Traceback (most recent call last):
File "./console.py", line 27, in ?
for cmd, callback in cmds:
ValueError: too many values to unpack

the code that is supposed to parse out the commands :
( all the commands are in a seperate file called
commands.py, just for ease of maintance and
readability )
---begin----
import commands

userInput = str()

while(1):

userInput == raw_input('ICE> ')
cmds = { 'help' : commands.displayHelp, 'version' :
commands.displayVersion,
'authors' : commands.displayAuthors, 'exit' :
commands.exitIce}

for cmd, callback in cmds:
if userInput == cmd:
callback()

-----end------

I've tried several methods of going around this error,
but none seem to work, the only other way i could do
it is with a big series of if and elif statments ..
but i don't reall want to for maintanance reasons ..


if i print cmds ( the array that holds the commands )
:

{'version': <function displayVersion at 0x403db17c>,
'exit': <function exitIce at 0x403dbc6c>, 'help':
<function displayHelp at 0x403d6f44>, 'authors':
<function displayAuthors at 0x403dbc34>}


Thanks
Bigbowser



__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail
 
Reply With Quote
 
 
 
 
Mathias Waack
Guest
Posts: n/a
 
      08-20-2004
Bigbowser wrote:
> while(1):
>
> userInput == raw_input('ICE> ')
> cmds = { 'help' : commands.displayHelp, 'version' :
> commands.displayVersion,
> 'authors' : commands.displayAuthors, 'exit' :
> commands.exitIce}
>
> for cmd, callback in cmds:
> if userInput == cmd:
> callback()


You mean

for cmd, callback in cmds.items()

?

Or much shorter:

cmds[cmd]()

Mathias
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.Net- 0 Build Errors, but I am prompted that there were build errors? Lance Wynn ASP .Net 1 02-03-2008 12:20 AM
Out-of-memory errors and caching errors. George1776 ASP .Net 2 09-14-2006 03:34 PM
Obsolete Errors and Deprecated Errors using Dotnet Framework 2.0 SenthilVel ASP .Net 0 06-07-2006 11:48 AM
Internet Explorer causing errors/ slow internet speed and Outlook express errors Jeanne Medley Computer Support 2 02-11-2004 11:44 PM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57