[Tutor] A command line
Tor Stormwall
tor@stormwall.org
Fri, 05 Oct 2001 20:51:32 +0200
Hi!
I'm trying make a little interpreter that will other run
commands.
But why cant I do like this:
import os
import sys
def commands():
if sys.argv[0] == open:
print "opening"
elif sys.argv[0] == exit:
sys.exit()
else:
print "not a valid command"
def interpreter(prompt='=> '):
try:
while 1:
command = raw_input(prompt)
try:
#flag = os.system('echo Hej')
if command:
commands() # calling "def commands()"
except (IndexError, KeyError):
print "'%s' not a valid command" % command
else:
pass
except EOFError: pass
interpreter()
Best Regards,
Tor Stormwall
--
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
| M A Y T H E S O U R C E B E W I T H Y O U |
| |
| Tor Stormwall mailto:tor@stormwall.org |
| http://www.creson.com/~tor |
| |
| http://www.sslug.dk http://www.stormwall.org |
| http://www.FreeBSD.org http://www.muf.se |
| |
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - *