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

Joe JoeSalmeri at hotmail.com
Thu Mar 3 07:54:03 EST 2005


Antoon,

I tested the batch file :-)

The one line batchfile does prove it because it prints out <backslash><n> 
and not <newline>.

See other post, decode is exactly what was needed to fix the problem.

Regards,

Joe

"Antoon Pardon" <apardon at forel.vub.ac.be> wrote in message 
news:slrnd2diqg.d87.apardon at rcpc42.vub.ac.be...
> 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