Questions tagged [readlines]

This tag refers to the `readlines` method available on file objects in Python.

The method's schematics are below:

readlines([size:int]) -> list of strings, each a line from the file.

readlines calls the readline method repeatedly and returns a list of the lines so read. The size argument, if supplied, sets an approximate bound on the total number of bytes in the lines returned.

499 questions
0
votes
3 answers

Open with 'rU' not recognizing endlines

I have a text file created by a Fortran program ran on SL6. It looks like: 1 R - Z binning n. 1 "1 " , generalized particle n. 223 R coordinate: from 0.0000E+00 to 1.1000E+02 cm, 110 bins ( 1.0000E+00 cm wide) Z…
0
votes
3 answers

A better method than readlines?

Using Python 2.5, I am reading an HTML file for three different pieces of information. The way I am able to find information is by finding a match with regex* and then counting a specific number of lines down from the matching line to get the…
teachamantofish
  • 75
  • 1
  • 1
  • 7
0
votes
2 answers

Loading Specific Data from a CSV file python

I am dealing with CSV files that contains lots of data. Each row contains data in the format as shown below. Name, Age, Sex, Birth Year Mark, 18, M, 1978 Mary, 18, M, 1980 Marcus, 18, M, 1978 This data is repeated so on and so forth for…
Newbie
  • 23
  • 2
  • 9
0
votes
1 answer

move through lines after using readline() python

I am currently attempting to parse two different types of files using python's csv module. In order to discover which file I am attempting to parse, I have to read the first letter of the second line. Depending on what that line says, I would like…
Micrasema
  • 41
  • 2
  • 8
0
votes
2 answers

Deleting a line from a text file

How to you delete a specific line from a text file using readlines() like: f_open = open("textfile.txt", "r") lines = f_open.readlines() How do you use lines to choose a line in textfile.txt and delete it? Sorry if it doesn't make sense.
user2396472
  • 47
  • 2
  • 2
  • 4
0
votes
1 answer

Read lines at different indexes

Here is some code i put together to search for numbers in a text file. It work's great for what i'm trying to do. right now it finds 7 locations and i need to read the lines at the 7 different indexes. what might be the best way to start this.…
DARCOM8
  • 53
  • 6
0
votes
1 answer

Read only lines that contain certain specific string and apply regex on them

Here's my code: I have a script that reads a file but in my file not all the lines are similar and I'd like to extract informations only from lines that have I DOC O:. I've tried with an if condition but it still doesn't work when there are lines…
Kirk ERW
  • 167
  • 1
  • 2
  • 14
0
votes
2 answers

How to read the pdf file in a line by line string in Python/Django?

I am dealing with the text and pdf file equal or less than 5KB. If the file is a text file, I get a file from the form and get the required input in a string to summarize: file = file.readlines() file = ''.join(file) result = summarize(file,…
pynovice
  • 7,424
  • 25
  • 69
  • 109
0
votes
1 answer

Foreach Loop File.Readlines displays nothing

I have a foreach loop that is supposed to display lines from a txt file when I click a button. Nothing is displaying when I click the button. What am I doing wrong? using System; using System.Collections.Generic; using System.Linq; using…
rupes0610
  • 261
  • 1
  • 6
  • 20
0
votes
2 answers

Python stdin, readlines. change output order

I am working from a Mac and have a question about a python for look. I am using a .txt file called rectangle.txt and inside the file it looks like this: abcde fghij klmno I need to read these in using stdin. But this is what I need my program…
Mac
  • 15
  • 3
0
votes
3 answers

Reading and sorting a 1D text file to a multidimensional array in python

I am attempting to read in a large data file and convert it to a format that my other scripts can better handle. Each datafile has a series of headers followed by two columns referring the relevant data points. This is then followed by another…
user1827345
  • 41
  • 1
  • 4
0
votes
1 answer

Reading a particular line by line number in a very large file

The file will not fit into memory. It is over 100GB and I want to access specific lines by line number. I do not want to count line by line until I reach it. I have read http://docstore.mik.ua/orelly/perl/cookbook/ch08_09.htm When I built an index…
user1645240
  • 55
  • 1
  • 7
0
votes
3 answers

Python read specific lines of text

I am having a problem reading specific lines. It's similar to the question answered here: python - Read file from and to specific lines of text The difference, I don't have a fixed end mark. Let me show an…
user1443368
  • 121
  • 1
  • 3
  • 9
-1
votes
1 answer

Identifying and extraction of its adjacent word from using readlines() and split() method in python

Would like to perform following operations. Step 1 -> From the *.k file would like to read all the lines. Step 2 -> Identifying specific word (Ex: "endtim") from this file. Step 3 -> Adjacent word t0 "endtim" identification.(Here Adjacent word ->…
-1
votes
0 answers

Python 3 fastest cross-platform way to read `\n` separated lines from a TCP socket

I'm writing a server which accepts TCP connections and reads arbitrary-length lines of data terminated by a \n. For this the semantics of socket.makefile(...).readline() does exactly what I need it to: f = socket.makefile(mode="rb") while True: …