[Tutor] Argparse Error

Steven D'Aprano steve at pearwood.info
Sun Aug 12 20:36:16 EDT 2018


Hi Nathan,

Let's talk about the process of debugging a technical problem and the 
sort of reasoning you might go through to solve these kinds of problems 
yourself. I know it all seems terribly mysterious and confusing right 
now, but as you learn to recognise what is going on, it becomes easier.

You wrote:
> Here is what comes out when I use the command for each program.
> 
> Command Prompt:
> C:\Users\natha> C:\WINDOWS\PROMPT> python D:\Python\bytsh.py
> D:\Video\test.mp4
> 'C:\WINDOWS\PROMPT' is not recognized as an internal or external command,
> operable program or batch file.

Here you are actually on the right track, you just didn't realise it.

The part "C:\Users\natha>" that displays at the beginning of each line 
is called the command prompt, or prompt. Unfortunately everyone's prompt 
is different. For example, here is mine:

    [steve at ando ~]$

But once you learn to recognise the various forms of prompts, and know 
not to retype them from examples, things start getting easier.

This is what Alan wrote:

    C:\WINDOWS\PROMPT>

Can you see the similarity between his generic placeholder prompt and 
your actual prompt? Both start with "C:\" and end with ">".

When you tried running Alan's example, you got this error message:

    'C:\WINDOWS\PROMPT' is not recognized ...

So the reasoning process a more experienced user might be:

    1. The command prompt looks like C:\...>

    2. Alan wrote something that looks like C:\...>

    3. Which the Windows shell didn't recognise as a command

Conclusion: 

Maybe the part of what Alan wrote that looks like the command prompt
was meant to be a placeholder for the real command prompt? In that case 
I shouldn't type it as part of the command. I should try again using:

     python D:\Python\bytsh.py D:\Video\test.mp4

after the real prompt, and see what happens next.

"What happens next" is, unfortunately, not necessarily that the bytsh.py 
program runs correctly and does what you expect. There could be all 
sorts of errors that occur:

- problems with the command (maybe Windows can't find "python");

- misspellings of the script name (did you mean "bytsh" or "bytes"?);

- bugs in the script (we still don't know if it works...);

- maybe even (but VERY unlikely) you discover a bug in Python.

Welcome to the joys of programming!

But each problem and error message you get, and solve, puts you one step 
closer to getting it working correctly.

Right now you might be feeling frustrated by these cryptic error 
messages, but I can tell you:

- it gets better with practice and experience;

- most error messages actually aren't that cryptic once you learn
  the jargon and know how to read them;

- and honestly, error messages are the programmer's best friend
  in the world.

If you think its bad to be presented with an error message, that's 
nothing compared to the frustration of being presented with a program or 
command that does nothing, in total silence.

(At least an error message gives you a handle to grab hold of and a way 
to investigate the problem. Silence gives you... nothing.)



Moving on to the next case:

>  Python 32x:
> >>> C:\WINDOWS\PROMPT> python D:\Python\bytsh.py D:\Video\test.mp4
>   File "<stdin>", line 1
>     C:\WINDOWS\PROMPT> python D:\Python\bytsh.py D:\Video\test.mp4
> 
> SyntaxError: unexpected character after line continuation character


I'll admit this one is pretty cryptic even to me, I had to think about 
it to understand what it is complaining about. But the details actually 
aren't important. The important part is

    SyntaxError

which tells you that this isn't even a line of valid Python code. The 
Python interpreter is expecting commands written in Python, and you've 
given it something which it cannot work out how to interpret. (It 
doesn't follow the rules of Python syntax.)

SyntaxError here strongly hints that you shouldn't be using this command 
at the Python command prompt >>> (and in fact, this is the case).

Hopefully you are now one step closer to being able to read these error 
messages for yourself. Good luck!


-- 
Steve


More information about the Tutor mailing list