GIDForums  

Go Back   GIDForums > Computer Programming Forums > Python Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Jun-2008, 20:16
stalepretzel stalepretzel is offline
New Member
 
Join Date: May 2008
Posts: 6
stalepretzel is on a distinguished road

Regexing files without memory problems


Hey all,

I'm making a few programs that do some regex work with files.

Currently, the program loops through an array created by readlines(). Then, it "regexes" each line. The problem is, this wont catch the pattern I'm searching for if it spans multiple lines. (Example: I'm searching for "cows" but the file contains co\nws).
One solution would be to read the ENTIRE file into memory, but that could eat up resources on a large scale. Does anyone have an idea for performing "cross-lines regex" without memory problems?

Thanks a bunch,
StalePretzel
  #2  
Old 12-Jun-2008, 22:25
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,627
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Regexing files without memory problems


Is the file formatted in such a way that you can read in a group of arbitrary lines, e.g. like a paragraph at a time? That way you don't have to read the whole file but you will still ensure all line spans are caught.

Alternatively you could just load into memory a set amount of data, e.g. 15KB, which will ensure you don't exceed your memory requirements. I don't know if this may lead to a missed span but it may worth a try.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
  #3  
Old 29-Nov-2008, 10:14
Mada Mada is offline
New Member
 
Join Date: Nov 2008
Posts: 1
Mada is on a distinguished road

Re: Regexing files without memory problems


Well you could always read the file with the read() method (which takes a size in bytes as an argument, and returns that information as a string) to get a whole "paragraph", and then apply the regex changes to another file.

But seriously, most computers today have enough memory to read very big files, those have to be quite heavy if you doubt on editing them as a whole.

regards

(six months later...)
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A Few Tips on Buying Good Memory Cards and other Hi-Tech Electronic Accessories haulkook Computer Hardware Forum 0 02-Jun-2008 04:53
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
out of memory problems pixienick MS Visual C++ / MFC Forum 1 25-Apr-2006 13:37
Bloodshed Dev C++ Project Options JdS C++ Forum 6 11-Nov-2005 18:23
[Tutorial] Pointers in C (Part I) Stack Overflow C Programming Language 1 08-Apr-2005 19:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:07.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.