I am getting an error and I don’t know how to refine my code.
Basically, what I am trying to do is pseudo echo command in a terminal app.
while True:
foo = input("~ ")
bar = str
if foo in commands:
eval(foo)()
elif foo == ("echo "+ bar):
print(bar)
else:
print("Command not found")
Obviously, it’s not working.
Does anybody know what I need to use to accomplish this project?
You create a variable
barand set it equal tostr, which is the string type. You then try to add this to the string"echo ". This obviously won’t work. What are you trying to do withbar?barisn’t connected to the user input, so it will never change no matter what the user types.If you want to see if the input begins with “echo” and then if so print the rest, you can do this:
strdoesn’t mean “any string”; it’s the type of all strings. You should read the Python tutorial to familiarize yourself with the basics of Python.