altering an object as you iterate over it?

netvaibhav at gmail.com netvaibhav at gmail.com
Sat May 20 03:18:58 EDT 2006


bruno at modulix wrote:
> fin = open(path, 'r')
> fout = open(temp, 'w')
> for line in fin:
>   if line.strip():
>     fout.write(line)
> fin.close()
> fout.close()
>
> then delete path and rename temp, and you're done. And yes, this is
> actually the canonical way to do this !-)

What if there's a hard link to path?


-- 
Vaibhav




More information about the Python-list mailing list