sub-shell errors

B

Bigbowser

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 ..
:p

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
 
M

Mathias Waack

Bigbowser said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top