Member Avatar

Well, in python I was planning to do something like this:

>> echo text

But I just cant find a way to do it!
I know that for user input i will use input(), but how do I get it to
echo the text specified?

Recommended Answers

All 2 Replies

OK, here for you start:

from __future__ import print_function
    input, range = raw_input, xrange
except NameError:

def quit_():
    raise SystemExit

def plus(a, b):
    return int(a)+int(b)

commands = {'echo':print, 'quit':quit_, '+':plus}

while True:
    c = input('>>').split(None, 1)
    if len(c) == 2:
        c, args = c
        args = args.split()
    elif c:
        c, args = c[0], []

        #empty line

        _ = commands[c](*args)
        if _ is not None:
    except KeyError:
        print('%s is not recognized command' % c)
    except TypeError:
        print('%s given wrong parameters: %s!' % (c, ' '.join(args)))
    except SystemExit:
        print('Bye, bye')
    except ValueError:
        print('Problem with values of parameters for %s: %s' % (c, ' '.join(args)))

>>ehco hi!
ehco is not recognized command
>>echo Hi, newbie!
Hi, newbie!
>>+ 12
+ given wrong parameters: 12!
>>+ 1 2.3
Problem with values of parameters for +: 1 2.3
>>+ 1 1
Bye, bye

Also have a look in standard module cmd, and also this code snippet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.