I know this is a basic question, but I'm having difficult with parsing some text.
So how the system will work, let's take the following example:
> set title "Hello world"
I should therefore get:
["set title", "Hello world"]
The problem is therefore, I need to split the string so when I enter, for example:
> plot("data.txt");
Should give me:
["plot", "data.txt"]
I have tried the following:
While True:
command = raw_input(">");
parse = command.split("' '");
if(parse[0] == "set title"):
title = parse[1];
But this does not work and will not even recognise that I am entering "set title"
Any ideas?
plot("data.txt")you'd get:['plot("data.txt")]since it doesn't contain any space. Why would the parenthesis disappear in the result? I believe you don't want to "split", you want to parse the command line into tokens. That's generally done with regexes.plot 'data.txt'not the one in the post, my badshlex.split(), it will preserve spaces inside strings. But that's not enough. There is no way to understand that you shouldn't split on the space ofset titlewith just a simple operation such as a "split" on a separator. You need a bit of more complex logic to check the tokens.