[Pythonmac-SIG] MemoryError Problem

Francois Granger fgranger@altern.org
Fri, 27 Apr 2001 11:12:28 +0200


At 22:46 -0400 26/04/01, in message Re: [Pythonmac-SIG] MemoryError 
Problem, Richard Gordon wrote:
>Of course it turned out that some of the files had unix endings 
>instead of windoze endings so I had to change things a bit:
>
>def strip(f):
>	global fcount
>	infh = open(f, 'rb').read()
>	os.rename(f, f +'~')
>	outfh = open(f, 'wb')
>	if infh.find('\r\n') != -1:
>		outfh.write(infh.replace('\n',''))
>	elif infh.find('\n') != -1:
>		outfh.write(infh.replace('\n','\r'))
>	else: pass
>	outfh.close()
>	fcount = fcount + 1
>	return

I did this some time ago for the same problem.
# -- line ending
f = open(file, 'rb')
temp = f.read()
f.seek(0)
crNum = string.count(temp, '\r')
lfNum = string.count(temp, '\n')
if lfNum == crNum:	# dos
	f.close()
	os.rename(file, join(doneFolder, split(file)[1][:27]) + '.dos')
	temp = string.replace(temp, '\n\r', '\n')
	f = open(file, 'w')
	f.write(temp)
	f.close()
	f = open(file)
elif crNum:
	f.close()
	os.rename(file, join(doneFolder, split(file)[1][:27]) + '.uix')
	temp = string.replace(temp, '\r', '\n')
	f = open(file, 'w')
	f.write(temp)
	f.close()
	f = open(file)

-- 
"Faites des phrases courtes. Un sujet, un verbe, un complément. Quand 
vous voudrez ajouter un adjectif, vous viendrez me voir." - Georges 
Clemenceau, 1841-1929, médecin et homme politique français. Consignes 
aux journalistes de "L'Aurore". d'après 
<http://www.sit.ulaval.ca/pagespersonnelles/phf/pensee.html>