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
2
votes
3 answers

python3: readlines() indices issue?

Python 3.1.2 (r312:79147, Nov 9 2010, 09:41:54) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> open("/home/madsc13ntist/test_file.txt", "r").readlines()[6] Traceback…
MadSc13ntist
  • 431
  • 1
  • 5
  • 8
2
votes
2 answers

Read and parse an irregular and mixed ASCII file into R

I'm still very new to R and I apologize if I'm not using the proper terminology. I'm interested in pulling a large amount of Unemployment Insurance Trust Fund data from the Treasury Direct online report query system…
KevinS
  • 23
  • 3
2
votes
2 answers

Process a line based on lines before and after in bash

I am trying to figure out how to write a bash script which uses the lines immediately before and after a line as a condition. I will give an example in a python-like pseudocode which makes sense to me. Basically: for line in FILE: if…
badner
  • 768
  • 2
  • 10
  • 31
2
votes
2 answers

paramiko-1.16.0 readlines() decode error

Doing a fairly standard paramiko implementation returns decode error on readlines() for oddly formed text from remote command. I can not change the command output. How can I write the code to properly decode. See decode error text at bottom: code…
Fragtzack
  • 373
  • 1
  • 5
  • 13
2
votes
1 answer

Verify if previous line have same string than current line and sum value of another column

What i'm trying to do is that such script reads the current…
Jontexas
  • 121
  • 8
2
votes
3 answers

Parsing a file with ".data" extension in Python?

I'm using idle in OS X, and I'm trying to parse a file with .data extension: FP = open('.data','r') lines=FP.readlines() print lines but this prints an empty array: [] I also tried Sublime but also doesn't work. What is another method…
makansij
  • 9,303
  • 37
  • 105
  • 183
2
votes
0 answers

how to read the last line of a txt file in R

I want to read the last line of a txt file by readLines in R, how can I achieve this? con<-file("test.txt","r") line<-readLines(con,n=-1) cat(line,"\n") close(con) the text file is as followed 3B1CHLH_PI210.PV 07-MAY-15 10:33:52.5 …
Cheng
  • 193
  • 3
  • 10
2
votes
4 answers

Python: search and print lines in a file by increments of 2

I am new so I hope this isn't redundant. Lets say I have an input file named "mccell" that looks like Initial Molecules: 47 Initial Molecules: 1 1 47 1 1 2 …
zww
  • 91
  • 2
  • 8
2
votes
1 answer

D Programming - How to get the piped content from stdin

I'd like to get the piped content in stdin of a D program only IF it is there. Considering the following string output; char[] buf; while (stdin.readln(buf)) { output ~= buf; } return output; This works great if you pipe content e.g echo…
keyle
  • 2,762
  • 3
  • 24
  • 27
2
votes
3 answers

Read lines from Multiple files

I have two files: A: John Kevin Richard B: Manager Salesperson Doctor I am trying to read lines from both the files simultaneously and print the following: Output: John is a Manager Kevin is a Salesperson Richard is a Doctor I tried using…
user3198755
  • 477
  • 2
  • 10
  • 21
2
votes
6 answers

ungetc in Python

Some file read (readlines()) functions in Python copy the file contents to memory (as a list) I need to process a file that's too large to be copied in memory and as such need to use a file pointer (to access the file one byte at a time) -- as in…
user78706
2
votes
3 answers

Python help - dictionaries, keys, values

I'm trying to write a program and I'm having a lot of trouble with it. Here are my instructions: For this program you are going to create a simple database from some U.S. Census data. The database will consist of a dictionary whose keys are the…
user3389793
2
votes
2 answers

Python readlines() and append data to each line output to one line

I have a csv file with say 3 rows like this: Dallas Houston Ft. Worth What I want to do is be able to read those in and make links out of them but have all the lines output on one line. Example output would need to be like this:
Matt
  • 163
  • 1
  • 3
  • 15
2
votes
1 answer

Using UTF-8 to open file for reading

I am using the below code but need to open it for reading with utf-8 specified. How would I do that please? infile = file(logPath) lines = infile.readlines()
speedyrazor
  • 3,127
  • 7
  • 33
  • 51
2
votes
0 answers

Extra characters in readlines and join python? How to remove ""? Byte Order Mark?

The python code: sku_specs = "./item_specs.txt" def item_specs(): g = open(sku_specs,"r") lines = g.readlines() lines = "<br />".join(lines) return lines f = open("ouput.txt","a") f.write("Some stuff"+item_specs()+"more…
jmunsch
  • 22,771
  • 11
  • 93
  • 114