LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2005, 11:23 PM   #1
JoeUser11
Member
 
Registered: Dec 2004
Location: Austin, TX
Distribution: SuSe9.3
Posts: 143

Rep: Reputation: 15
Python readlines


Right now I'm working on a python program that solves anagrams. Pretty much I need to compare the number of each letter out of a given word with the number of each letter in every single word in the dictionary. I was using string.readlines(), but the dictionary list I'm using is so big that it is causing problems. I'm pretty much just trying to read in every line of a 2.4 meg text file, but IDLE just freezes when I attempt it. Anybody see any way around this problem?
 
Old 03-02-2005, 12:10 AM   #2
nulldevice
LQ Newbie
 
Registered: Feb 2005
Posts: 4

Rep: Reputation: 0
use readline instead of readlines. using readlines for files which are larger in size is not a good idea.
 
Old 03-02-2005, 01:52 AM   #3
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
FYI: In recent Python versions, thanks to iterators, you no longer need to call readline explicitly:

Code:
fp = open(r"file.txt","r")
for line in fp:
   print line
 
Old 03-02-2005, 06:46 AM   #4
JoeUser11
Member
 
Registered: Dec 2004
Location: Austin, TX
Distribution: SuSe9.3
Posts: 143

Original Poster
Rep: Reputation: 15
thanks coolman, that worked like a charm.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Processing Conflict: python-devel conflicts python< 2.3.4-13.1 guarriman Fedora 2 04-23-2009 07:02 PM
installing python library's (Python Numeric) Four Linux - Newbie 1 10-16-2005 02:31 PM
Python guru's - Is this a python bug? or is it me? bardinjw Programming 2 06-23-2005 08:17 AM
WineX, python-gnome, and python-gtk DrD Fedora 0 08-03-2004 12:11 PM
install python 2.3 ,necssary to remove python 2.2 ngan_yine Linux - Newbie 7 12-28-2003 04:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration