[Tutor] create an xls file using data from a txt file
Steve Willoughby
steve at alchemy.com
Thu May 12 01:24:27 CEST 2011
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.
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).
> 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
More information about the Tutor
mailing list