[Pythonmac-SIG] MemoryError Problem

Richard Gordon richard@richardgordon.net
Thu, 26 Apr 2001 22:46:40 -0400


--============_-1223782882==_ma============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

At 12:29 PM +0200 4/26/01, Francois Granger wrote:

hi Francois & thanks for the response.

>Have a look to the module /lib/module-fileinput.html in the HTML
>documentation

I've used fileinput before and could never get the command line 
switch to modify files in place to work- it looked like it was just 
creating temp files even if this did work which is what prompted me 
to just start from scratch.

>
>def strip(f):
>    global fcount
>    infh = open(f, 'rb').read()

Gadzooks, using read() works fine while both xreadlines() and 
readlines() fail at about the same point! I'm not quite sure why 
that's the case but I appreciate the suggestion. 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

This works well and converted 294 files in 77 seconds on my aging 
8100->G3. As an aside, the main reason that I have this recurring 
need to change endings is that Stuffit 5.5's line conversion facility 
is broken and has to be disabled or you wind up with all kinds of 
strange messes. Now all I have to do is decide how to get rid of the 
original 294 files that have become *.py~ relics.


Richard Gordon
--------------------
Gordon Design
Web Design/Database Development
http://www.richardgordon.net
--============_-1223782882==_ma============
Content-Type: text/enriched; charset="us-ascii"

At 12:29 PM +0200 4/26/01, Francois Granger wrote:


hi Francois & thanks for the response.


<excerpt>Have a look to the module /lib/module-fileinput.html in the
HTML

documentation

</excerpt>

I've used fileinput before and could never get the command line switch
to modify files in place to work- it looked like it was just creating
temp files even if this did work which is what prompted me to just
start from scratch.


<excerpt>

def strip(f):

    global fcount

    infh = open(f, 'rb').read()

</excerpt>

Gadzooks, using read() works fine while both xreadlines() and
readlines() fail at about the same point! I'm not quite sure why that's
the case but I appreciate the suggestion. 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:


<fontfamily><param>Monaco</param><smaller>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


</smaller></fontfamily>This works well and converted 294 files in 77
seconds on my aging 8100->G3. As an aside, the main reason that I have
this recurring need to change endings is that Stuffit 5.5's line
conversion facility is broken and has to be disabled or you wind up
with all kinds of strange messes. Now all I have to do is decide how to
get rid of the original 294 files that have become *.py~ relics.



Richard Gordon

--------------------

Gordon Design

Web Design/Database Development

http://www.richardgordon.net

--============_-1223782882==_ma============--