Hey no fair changing last names in the middle of a thread :-)
Thanks to BOTH Steve's.
> In fairness it was Steven Bethard's solution that gave you the solution
> you needed. As long as ytour problem is solved, that's fine, and it
> appears that you've solved it in a reasonably cross-platform w
Joe wrote:
Hi Steve,
I've been using Python for many years, just hadn't had to deal with an
escape sequence in the command line args. :-) and couldn't find the solution
in the docs.
It is easy to prove my assertion:
import sys
c = sys.argv[1]
print len(c)
print 'Line 1', c, 'Line 2'
Output:
2
Li
Antoon,
I tested the batch file :-)
The one line batchfile does prove it because it prints out
and not .
See other post, decode is exactly what was needed to fix the problem.
Regards,
Joe
"Antoon Pardon" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Op 2005-03-02, Joe schre
Hi Steve,
I've been using Python for many years, just hadn't had to deal with an
escape sequence in the command line args. :-) and couldn't find the solution
in the docs.
It is easy to prove my assertion:
import sys
c = sys.argv[1]
print len(c)
print 'Line 1', c, 'Line 2'
Output:
2
Line 1 \n
Op 2005-03-02, Joe schreef <[EMAIL PROTECTED]>:
> 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
> Here is a sample.py
Joe wrote:
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"
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
Steve,
THANKS! That is exactly what I was looking for but unable to find.
Joe
"Steven Bethard" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Joe wrote:
>> It appears that Python treats the comand line string as a raw string.
>>
>> what is the best way to work around the issue?
Joe wrote:
It appears that Python treats the comand line string as a raw string.
what is the best way to work around the issue?
You probably want to use str.decode with the encoding 'string_escape'[1]
py> s = r'\n\t'
py> s
'\\n\\t'
py> s.decode('string_escape')
'\n\t'
STeVe
[1]http://docs.python.or
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"
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
t