Im working on a parser here that opens a file, reads it and prints data in another file.
The input file is determined from sys.argv[1] to both handle commandline opening and drag and drop (in windows). However, when drag and dropping a file, it gives me
ioerror 13: Permission denied
Looking at what sys.argv contained, I did the following (from cmd.exe) to have it contain the same:
C:\>python C:\test\iotest.py C:\test\iotestin.txt
It failed. However, the following works
C:\>cd test
C:\test>python iotest.py iotestin.txt
To me, the above would/should be virtually the same.
- Why do I get the permission error?
- How do I make python able to handle fully specified paths? (If thats the problem.)
- How do I enable drag and drop?
Oh, and if its unclear, I drag the input/txt file to the python file, not the other way around. As a coder, I always prefer a CLI, but the future users of this software do not, hence I need to get this working.
Although extremely simple, heres some code to reproduce the problem:
import sys
print sys.argv
raw_input("")
try:
print "opening",sys.argv[1]
infile = open(sys.argv[1])
outfile = open("out.txt", "w")
raw_input("")
except IndexError:
print "usage:",sys.argv[0].split("\\")[-1],"FILE"
raw_input("")
exit()
except IOError as (errno, strerror):
print "I/O error({0}): {1}".format(errno, strerror)
raw_input("")
exit()
raw_input("done")