newbie question(file-delete trailing comma)

Mikael Olofsson mikael at isy.liu.se
Tue Feb 27 08:05:18 EST 2007


kavitha thankaian wrote:
> i get an error when i try to delete in file and rename it as out 
> file,,the error says
> "permission denied".

Perhaps you should give us both the exact code you are running and the
complete traceback of the error. That could make things easier. There
can be numerous reasons for "permission denied".

> actually i need something like following:
>  
> in_file = open('in.txt','w')
> for line in in_file:
>     line.strip().strip(',')
>  
> but when i run the above code,i get an error"bad file descriptor"

Of course you do! You are opening the file for writing, but your code
attempts to read the file. Probably, you think that the code would
change the lines in the file itself, which it does not, even if it would
be possible to read from a file opened for writing.

What's wrong with the code that Mohammad posted? Note that you might
need to close out_file in his code.

/MiO



More information about the Python-list mailing list