What is the best way to handle a command line argument that includes an escape sequence like \n?

Antoon Pardon apardon at forel.vub.ac.be
Thu Mar 3 09:31:13 CET 2005


Op 2005-03-02, Joe schreef <JoeSalmeri at hotmail.com>:
> I'm using Python 2.4 on Windows XP SP2.
>
> I'm trying to receive a command line argument that is a newline (\n)
>
> Here is the command line to use
>
> sample.py "\n"

Are you sure this supplies a newline and not the string <backslach> <n>

> Here is a sample.py script
>
> import sys
>
> c = sys.argv[1]
>
> # when run c is set to \\n instead of \n.
>
> I created a test batch file
>
> echo %1
>
> to confirm that it was not the cmd.exe command processor causing the issue.

I'm not sure this confirms anything. IMO it is possible that echo
will translate <backslach> <n> to <newline>, giving you the
impression that you have provideded a newline on the command line
while in fact you have not.

-- 
Antoon Pardon



More information about the Python-list mailing list