tzot at sil-tec.gr
Sat Mar 18 13:51:38 CET 2006
On Fri, 10 Mar 2006 16:43:15 +0200, rumours say that Juho Schultz
<juho.schultz at helsinki.fi> might have written:
>> Hi All
>> Basically i want to write into a file .If the permissions are not there
>> then print a error message.
>> How do i achive this ???
>One way would be a try-except block, and leave the permission checking
>error message generation, etc. to the operating system.
> outfile = file(outfilename,"w")
>except IOError, errormsg
> print "Could not write to file %s: %s" % (outfilename, errormsg)
As a word of caution: the OP is checking for the permissions of an
*existing* file. Both Juho's and Sybren's suggestions *destroy* the file's
So, VJ, I'd suggest the following change:
Open the file for read write
outfile= open(outfilename, "r+b") # I assume binary
and later on catch errors in .write operations.
TZOTZIOY, I speak England very best.
please stop spamming us."
More information about the Python-list