[Tutor] Number Coercion: I swear, I never laid a hand on it!

kromag@nsacom.net kromag@nsacom.net
Wed, 24 Oct 2001 12:21:29 -0700 (PDT)


Hi everybody,

I have been trying to write a silly little menu script just to figure out how:

-------------silly menu script-------------

import os
import string
import sys


menu_items={'edit': '\windows\command\edit.com',
	'vim': '\vim\vim57\gvim.exe'}

print 'menu choices'
print menu_items.keys()

choice = raw_input()

if menu_items.has_key(choice):
	os.system('s%')% menu_items[choice]
else:
	sys.exit('Sorry, try again.')

---------end silly menu script-------------

For some reason, I get a problem with: 

	os.system('s%')% menu_items[choice]

which gives this number coercion error:

-------------error-------------------------

C:WINDOWSDESKTOP>python menu.py
menu choices
['vim', 'edit']
vim
Bad command or file name
Traceback (most recent call last):
  File "menu.py", line 15, in ?
    os.system('s%')% menu_items[choice]
TypeError: number coercion failed

---------end error-------------------------

I stand confused.

d