Can't Write File

Rami Chowdhury rami.chowdhury at gmail.com
Wed Nov 11 11:54:45 EST 2009


On Wed, 11 Nov 2009 08:42:27 -0800, Victor Subervi  
<victorsubervi at gmail.com> wrote:

> On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury
> <rami.chowdhury at gmail.com>wrote:
>
>> On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi <
>> victorsubervi at gmail.com> wrote:
>>
>>  On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel <davea at ieee.org> wrote:
>>>
>>>  Victor Subervi wrote:
>>>>
>>>
>>  Wrong?
>>>>
>>>> 2) you don't show the error traceback
>>>>
>>>>  because there are none
>>>
>>>            try: # It does this, because I've printed 'getpic1.py' etc.
>>>              getpic = "getpic" + str(w) + ".py"
>>>              try:
>>>                os.remove(getpic)
>>>              except:
>>>                pass
>>>
>>
>> There are no error tracebacks because you're deliberately suppressing  
>> them
>> with the except: clause above. A bare except: clause *may* be  
>> acceptable in
>> production code, where you may *want* to silently ignore all errors,  
>> but if
>> you're trying to debug something then it's really not helpful.
>>
>
> Well, that's the *only* place where I do so, and I dare say that in that
> case, it makes all the sense in the world. If there is no file getpic to
> remove, then don't worry about it!

Sure, and that's your decision to make... in an environment where you know  
everything else is working fine and the *only reason* that os.remove file  
is failing is that the file isn't present. If it's failing due to a  
permissions error, for instance, you won't be any wiser. I'd suggest  
removing that except clause, seeing what exception is actually raised, and  
posting that to the list.

> No, that's not where the error is.Please
> suggest something else.

if os.path.exists(getpic):
	os.unlink(getpic)
else:
	print "File %s could not be found!" % getpic



-- 
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)



More information about the Python-list mailing list