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

Reading a specific line in Julia

Since I'm new in Julia I have sometimes obvious for you problems. This time I do not know how to read the certain piece of data from the file i.e.: ... stencil: half/bin/3d/newton bin: intel Per MPI rank memory allocation (min/avg/max) =…
kata248
  • 59
  • 4
2
votes
2 answers

TDMS file read data in python

During the project, I had to deal with a TDMS file. I'm asking because the file could not be read immediately. My Goal: Perform analysis by converting TDMS file into DataFrame format First attempt, -Perform TdmsFile open using npTdms…
Okgukui
  • 23
  • 1
  • 3
2
votes
4 answers

printing lines from a file within an inclusive alphabetical range not including desired limits

The trouble I'm having with this program is that it is not including the bounds even though I use the >= <= operators. Also for some reason the words that are output are each separated by a newline rather than printing one after another. For…
Drkdeibs
  • 103
  • 1
  • 1
  • 8
2
votes
3 answers

Read a specific line from a text file then check if it's equal to a string variable?

I am trying create a login system. The user creates their account and inputs the username and password they would like to use. The username gets stored in line 1 of a new text file. The password gets stored in line 2 of the text file. Now I open…
2
votes
0 answers

R code executes when run line by line but not all at once

I am trying to read multiple lines in from a TCP web socket. When I run the following lines one at a time in the RStudio console, I get the data in the expected values and format. When I try to run them together (as part of a larger script or simply…
srs025
  • 88
  • 5
2
votes
5 answers

How can i read one specific line and 7 more lines under that one

i have this big txt file G29 2019 07 08 02 00 00 1.571122556925e-04-9.777068044059e-12 0.000000000000e+00 6.100000000000e+01 6.809375000000e+01 3.670867192067e-09 2.120402980941e+00 3.512948751450e-06 1.192553318106e-03 9.380280971527e-06…
2
votes
5 answers

How to read a specific portion of a txt file in Python?

I need to extract a portion of text from a txt file. The file looks like this: STARTINGWORKIN DD / MM / YYYY HH: MM: SS ... text lines ... ... more text lines ... STARTINGWORKING DD / MM / YYYY HH: MM: SS ... text lines I want ... ... more…
Y4RD13
  • 937
  • 1
  • 16
  • 42
2
votes
2 answers

How to simultaneously read and write a file line by line?

I would like to remove all lines from a file which start with a certain pattern. I would like to do this with R. It is good practice to not first read the whole file, then remove all matching lines and afterwards write the whole file, as the file…
Marius Hofert
  • 6,546
  • 10
  • 48
  • 102
2
votes
6 answers

Reading and print string x times

I have an assignment where I have a text file with a word on each line which forms a string. On some lines there are a number with which amount of times I have to print the string, separated by a comma and space and finish with a period For…
Thomas Bengtsson
  • 399
  • 2
  • 10
  • 22
2
votes
2 answers

How to get a phrase from a line number in python?

I have a list of URLs and I would like to get the URL from a specific line. For example, from this file bellow: urls.txt http://www.google.com http://www.facebook.com http://www.stackoverflow.com I would like to create a function that I give the…
rafasalo
  • 243
  • 2
  • 16
2
votes
2 answers

How to input a list of URLs saved in a .txt to a Python program?

I have a list of URLs saved in a .txt file and I would like to feed them, one at a time, to a variable named url to which I apply methods from the newspaper3k python library. The program extracts the URL content, authors of the article, a summary of…
2
votes
4 answers

Python delete line from CSV based on date

I am using python to collect temperature data but only want to store the last 24 hours of data. I am currently generating my .csv file with this while True: tempC = mcp.temperature tempF = tempC * 9 / 5 + 32 timestamp =…
SR.
  • 23
  • 5
2
votes
5 answers

How to split elements in a list and get date and time from a list

Since the beginning of time I have been struggling with importing files in Python and reading lines in a optimal way. For example, a file I have is as follows: 2015 02 25 09:00:00 A second line One more line Now I want to extract the date and…
Jordy
  • 39
  • 1
  • 4
2
votes
1 answer

How to read all lines of text file to return if a value is present and then write this value if not present?

I'm a bit confused about reading my txt file with Python and then appending it a value. What I'm trying to achieve is to call an API, retrieve the id of the latest object, and check if this id is already in the list of object previously retrieved…
Pedro MS
  • 48
  • 8
2
votes
2 answers

Python: processing lines of a large document on the fly

I have a document that looks a bit like this: key1 value_1_1 value_1_2 value_1_3 etc key2 value_2_1 value_2_2 value_2_3 etc key3 value_3_1 value_3_2 value_3_3 etc etc Where each key is a string and each value is a float, all separated by spaces.…
Mike S
  • 1,451
  • 1
  • 16
  • 34