Python: 'q)+' is not recognized as an internal or external command

438 views Asked by At

Python newbie here.

I have a program named zeroOrMore.py

It reads a regular expression (regex) from stdin.

I invoke the program like this:

python zeroOrMode.py (ab)*(p|q)+

That results in this error message:

'q)+' is not recognized as an internal or external command, operable program or batch file.

I discovered that if I enclose the regex in double quotes:

python zeroOrMode.py "(ab)*(p|q)+"

then there is no error.

Is there a way to accomplish this without wrapping the regex in double quotes? Here's how my program inputs the regex:

regex = sys.argv[1]
1

There are 1 answers

0
kirbyfan64sos On BEST ANSWER

This isn't Python; it's CMD. The regex you're giving to Python is being interpreted by the command prompt first. The pipe (|) is the batch command for piping input to the following program. Basically, CMD is reading the command line like so:

python zeroOrMode.py (ab)*(p    |    q)+

It's trying to take the result of running zeroOrMode.py (I think you meant more?) with (ab)*(p and piping the output to the (nonexistent) program q)+.

There isn't really much of a solution to this, unfortunately. You could always escape the pipe like so:

python zeroOrMode.py (ab)*(p^|q)+

The caret (^) will cause any special meanings the next character has to be ignored.