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
1 answer

Python: readlines()-method creates empty lists

I'm trying to parse items from a text file with lines of text separated by semicolons like this: 4037;HKO_2005;OBJECT-ORIENTED PROGRAMMING ;18.12.2011;5 4037;HKO_2009;DATABASES I …
jonraem
  • 175
  • 1
  • 1
  • 10
0
votes
1 answer

Ruby find a string in a text file and output the line it's found on

I need to add the functionality to output the entire line a string is found on. So here's the code I have working so far. if type == "asa" if File.readlines(file).grep(/http server enabled/).any? $httpserver_failures.push(file) …
Darkmatter5
  • 1,189
  • 3
  • 12
  • 19
0
votes
1 answer

Groovy Reader HashSet on readLines() returns out of order

I'm VERY newb at Groovy (and most back end.) I'm typically a JS developer, so bear with me. I have a static .txt file that's holding a manifest, one item per line: asdf/asdf/rewer.js asdf/asdf/opuio.js asdf/asdf/rnieo.js asdf/asdf/tewoe.js I have…
Randy Hall
  • 7,716
  • 16
  • 73
  • 151
0
votes
2 answers

Open text file, print new lines only in python

I am opening a text file, which once created is constantly being written to, and then printing this out to a console any new lines, as I don't want to reprint the whole text file each time. I am checking to see if the file grows in size, if it is,…
speedyrazor
  • 3,127
  • 7
  • 33
  • 51
0
votes
3 answers

Getting values from file if match found for lines with same id in Python

I have a file with lines of data. Each line starts with an id, followed by fixed set of attributes separated by comma.…
Cryssie
  • 3,047
  • 10
  • 54
  • 81
0
votes
3 answers

Python reading and printing text file

I am reading in a text file and printing the contents, but am getting the below result, instead of line breaks, etc, which when opening the text file I can see, it is printing out \n along with other characters. How do I change the printing to…
speedyrazor
  • 3,127
  • 7
  • 33
  • 51
0
votes
1 answer

How to compare two text files with value in ruby

I have two text file, and they have one same field(pet). I want to combine two file and output a new file contain three fields(owner pet buyer). My code is mainly depends on if both file have the same pet(name and number of pets) than I will add the…
Michael
  • 65
  • 1
  • 7
0
votes
1 answer

How can I get readlines() to ignore the EOF 0x1A character?

I am writing a Python script that will take STDIN from TextWrangler and do something to it on a line by line basis. In Textwrangler, I combine multiple text files using drag and drop. Problem is that the documents retain the ^Z (0x1A) character,…
0
votes
1 answer

R, readLines, strsplit and grep

I am trying to read a random text file one line at a time. Then split the line into "words" and perform some regex on each word, like finding all word that start with "w". After the following like code snippet I get: while (length(oneLine <-…
user2970161
  • 11
  • 1
  • 4
0
votes
1 answer

Remove repeating lines of characters when reading text files in python?

I am reading a text file which was copied from a CSV file. When I read the file in python, I get a ton of unnecessary repeating lines as seen below. How can i strip away those three unwanted lines, including \cf0 and \cell\row at the beginning and…
jxn
  • 7,685
  • 28
  • 90
  • 172
0
votes
2 answers

Understanding code from K&R

I'm reading K&R for my c language course, I have question in function readlines from section 5.6: /*readlines: read input lines*/ int readlines(char *lineptr[], int maxlines) { int len, nlines; char *p, line[MAXLEN]; nlines=0; …
Assaf
  • 1,112
  • 4
  • 14
  • 35
0
votes
0 answers

what file size do we need replicate "Cannot read from a closed TextReader" error?

Had got this error in my program. Came across a few posts which kind of gave me the idea that this issue is probably due to file size. As far as my program is concerned, the observation I find is for small file sizes I do not get this error. For a…
deostroll
  • 11,661
  • 21
  • 90
  • 161
0
votes
1 answer

python parsing input, making a sum of the input

I am attempting to parse a file with the following format 1999 I Willem Jan van Steen 9859 77 Guillaume Kielmann 5264 77 Guillaume Bos 8200 6 (the file is much longer, and is seperated by academic year (as…
0
votes
1 answer

R formule with readLines

I'm new in R and am trying to make a formula with the function readLines, but all the time R returned the same errors and do not know how to fix it. Any suggestions? my formula sam.cover<-function(){ readLines()->CH …
Maria
  • 1
  • 2
0
votes
2 answers

R - readLines outputs empty lines

I have encountered some strange behaviour of the readLines()-function which is basically included for all R-runs. As I have done it houndreds or thousands of times before, I tried to read the lines of a file like this: workingDir <- "" tempFile <-…
Florian R. Klein
  • 1,375
  • 2
  • 15
  • 32