473,769 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MemoryError in Python script

1 New Member
Hi,
I have written a small python script to parse a very large data set. It works for sometime and then stops with an error message:

Traceback (most recent call last):
File "./tmveritracepars er.py", line 33, in ?
for lineStr in fin.xreadlines( ):
MemoryError



Code snippet is:
Expand|Select|Wrap|Line Numbers
  1. for lineStr in fin.xreadlines():
  2.     operAddress = ParseLine(lineStr)
  3.     address = operAddress[2].split('x')
  4.     if (operAddress[1] == 'write'): 
  5.         fout.write("%5s write %5s \n" % (operAddress[0], address[1]))
  6.     if (operAddress[1] == 'read'):
  7.       #  print operAddress[0] +  address[1]
  8.         fout.write("%5s read %5s \n" % (operAddress[0], address[1]))
  9.     else:
  10.         continue
Any idea how it could be solved?
Thanks in advance,
M
Aug 30 '07 #1
1 2559
bvdet
2,851 Recognized Expert Moderator Specialist
Hi,
I have written a small python script to parse a very large data set. It works for sometime and then stops with an error message:

Traceback (most recent call last):
File "./tmveritracepars er.py", line 33, in ?
for lineStr in fin.xreadlines( ):
MemoryError



Code snippet is:

for lineStr in fin.xreadlines( ):
operAddress = ParseLine(lineS tr)
address = operAddress[2].split('x')
if (operAddress[1] == 'write'):
fout.write("%5s write %5s \n" % (operAddress[0], address[1]))
if (operAddress[1] == 'read'):
# print operAddress[0] + address[1]
fout.write("%5s read %5s \n" % (operAddress[0], address[1]))
else:
continue

Any idea how it could be solved?
Thanks in advance,
M
The file method 'xreadlines()' is obsolete. Try iterating on the file object:
Expand|Select|Wrap|Line Numbers
  1. fin = open('file_name')
  2. fout = open('file_name1', 'w')
  3.  
  4. for lineStr in fin:
  5.     operAddress = ParseLine(lineStr)
  6.     address = operAddress[2].split('x')
  7.     if (operAddress[1] == 'write'):
  8.         fout.write("%5s write %5s \n" % (operAddress[0], address[1]))
  9.     elif (operAddress[1] == 'read'):
  10.         # print operAddress[0] + address[1]
  11.         fout.write("%5s read %5s \n" % (operAddress[0], address[1]))
There is no need for the else-continue statement unless you are skipping code that follows. I was guessing your code indentation. Try using code tags next time.
Aug 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1796
by: Andy Rechenberg | last post by:
The problem is basically in the subject line. I am building an Intranet site based on Zope/CMF/Plone. In order to fulfill the requirements Zope/Python must be run on Windows. Zope is running as a Wi32 service. When the python.exe process consume ~122MB (according to the Windows Task Manager) I start receiving MemoryError: out of memory exceptions. I've already checked for bad RAM and the server's RAM appears good.
2
2057
by: Sylvain Thenault | last post by:
Hi there ! I've noticed the following problem with python >= 2.3 (actually 2.3.4 and 2.4): syt@musca:test$ python Python 2.3.4 (#2, Sep 24 2004, 08:39:09) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import parser >>> parser.suite('# -*- coding: IBO-8859-1 -*-')
0
1207
by: Bernhard Reimar Hoefle | last post by:
I have the following python script: ####################################### from numarray import * while 1: a=arange(1,300000000) b=a*100/100 del a del b #######################################
0
1334
by: Stephen G | last post by:
Hi there. I have been receiving MemoryErrors using the Windows version of Python 2.5. The script I have written times the sending and the reception of emails with various attachments. I get many exceptions when using the IMAP downloads. This happens randomly; sometimes the file downloads OK, and other times no. Using an exception and traceback function, I can see the following... MemoryError <no args> File "C:\Documents and...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.