[Tutor] create an xls file using data from a txt file

Prasad, Ramit ramit.prasad at jpmchase.com
Thu May 12 15:27:00 CEST 2011


>Respectfully, I think you aren't clear on how command line execution 
>works.  Hopefully I can help a little (yes, there are enough cases where 
>it'll bite you that it's good to know this).

True

>If Windows natively supported it, then you could do this:
>C:\> DIR /users/fred/desktop
>C:\> DEL /temp/myfile
>Or try running your Python program like
>C:\> /python27/python.exe scriptname.py
>That doesn't work either, because Windows is NOT in any way at all 
>interpreting the / characters.
> C:\> /python27/python.exe scriptname.py

Oh, really? Works for me. 
C:\>/Python31/python.exe /temp/test.py
  File "/temp/test.py", line 1
    print 'Hello World'
                      ^
SyntaxError: invalid syntax


True that does not work for dir and del because both use '/' as the argument passing prefix, but that does not mean that Windows cannot handle it.

Ramit



Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

-----Original Message-----
From: Steve Willoughby [mailto:steve at alchemy.com] 
Sent: Wednesday, May 11, 2011 6:24 PM
To: Prasad, Ramit; tutor at python.org
Subject: Re: [Tutor] create an xls file using data from a txt file

On 11-May-11 15:54, Prasad, Ramit wrote:
>> Core windows commands don't generally accept it, including native
>> Windows applications (although sometimes they're lenient in what they
>> accept).  It'll work for command-line Python script usage because it's
>> *python* that allows them, not *windows*.
>
> They work in *Windows* command prompt natively.

> Some apps do not work well that is true, but the reason that theywork like this with Python is NOT because Python allows it but because 
Windows does. I highly doubt Python checks for "/" and converts it to 
"\\" (or does any complicated checking of file strings). YMMV for apps, 
but I have never had a problem with '/' on the command prompt. It is an 
important caveat to note that this behavior is not Guaranteed.

Actually, yes, that's exactly what Python (or actually the underlying 
file handling libraries it's built with) is doing on Windows.  There is 
a decades-long tradition of C compilers (et al) doing this conversion 
for the sake of all the ported Unix C programs that people wanted to run 
on Windows (or, at the time, MSDOS).

If Windows natively supported it, then you could do this:

C:\> DIR /users/fred/desktop
C:\> DEL /temp/myfile

Or try running your Python program like

C:\> /python27/python.exe scriptname.py

That doesn't work either, because Windows is NOT in any way at all 
interpreting the / characters.

So why does this work:

C:\> myscript.py /temp/myfile /users/fred/desktop

or even

C:\> \python27\python.exe myscript.py /temp/myfile

That works because Windows hands ALL of the argument strings, as-is, 
with NO interpretation, to the application to deal with.  In this case, 
the application is Python, and Python is going to the extra work to 
interpret the / characters as \ characters when you try to use them in 
open() calls and the like.

-- 
Steve Willoughby / steve at alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C
This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase &
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.


More information about the Tutor mailing list