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
1
vote
4 answers

Python Write lines of a text in between a range of numbers to a new file

Sample Text File: 1. some text here 2. more text here more text here more text here more text here 3. more text here more text here more text here more text here 4. more text here more text here more text here more text here 5. more text here more…
JareBear
  • 467
  • 9
  • 27
1
vote
1 answer

Checking if date is overdue from text file

I have a text file that has users and then due dates. I would like to be able to read the due date which was initially input by the user and see if the date is overdue compared with the current date. Any help would be appreciated. Text file: User:…
NoobDev88
  • 23
  • 6
1
vote
1 answer

How can i create list of lists from file where every list would have more than one line?

i have this big file, E01 2019 07 07 23 50 00-6.423263694160e-04-8.043343768804e-12 0.000000000000e+00 1.500000000000e+01-8.437500000000e+00 2.970480875309e-09-8.238142721997e-02 -3.967434167862e-07 1.850683474913e-04 6.241723895073e-06…
1
vote
2 answers

The line is splitting at the wrong place

I'm having problem splitting a lines from a '.txt' file. I want the line to split at the ',' but it splits each character even when the .split() function has a parameter. Can someone show me what I've done wrong and how it could be fix or even…
t0mas
  • 127
  • 14
1
vote
1 answer

why not rewrite the text in the file .txt file , even though the code was processed correctly?

When the code is run, it executes correctly and no errors appear, and the results are expected, but the file is not "overwritten". What is the solution? Rewrite the file even though the code is correct and there are no errors! space_indecies = [2,…
1
vote
2 answers

Why is my if statement not executing properly?

I'm trying to practice my python skills, I knew that I was kind of unfamiliar with how to work with files so I decided to teach my self. The code is basically making an account, signing in and checking the user and pass stored in a file. I know my…
Nick_M
  • 17
  • 2
1
vote
1 answer

I have a list of bytes and I want a list of strings

I want to take the first line of a file opened from an url, search for a specific string and then split that string. request=urllib.request.Request(url) response=urllib.request.urlopen(request) input_file=response.readlines() for l…
Chloe
  • 19
  • 2
1
vote
1 answer

How to select random line in file using readlines() with a previously random generated integer?

I've got some code for a specific goal, to load a page with a proxy, chosen from a list via random number. Every time I run it, the same proxy is selected from the list, even though it's a different random integer every time. I've got the code…
1
vote
2 answers

How to read certain lines from a text files while ignoring few lines in between using R (also delimit those lines into columns)?

I have a water balance text file of which first 20 lines are not necessary for analysis. Then I have a column names line which I want to preserve and again a line with units and then hyphens I want to ignore. Then I have the data which I want to get…
Samrat
  • 79
  • 1
  • 10
1
vote
4 answers

Jump into the next line in readlines inside for loop

I am writing a code to extract something useful from a very big Source.txt file. A sample of my source test file is as below: Test case AAA Current Parameters: Some unique param : 1 Some unique param : 2 Some unique param : 3 …
Hari
  • 718
  • 3
  • 9
  • 30
1
vote
1 answer

How to read in a file and have its variable name automatically take on the file name?

How can I use something like readLines to save the file as a character string in my environment with its own file name as the variable? I tried something like the pseudocode below without success. paste(filename) <- readLines(filename)
hmnoidk
  • 545
  • 6
  • 20
1
vote
1 answer

How to avoid lines that contain both string and numbers before splitting them?

I use python 3, and I read files that strart with few lines that contain text and number together, and from a certain line it's only columns of numbers, that originally they are also read as str after splitting, that I later convert them to…
FabioSpaghetti
  • 790
  • 1
  • 9
  • 35
1
vote
4 answers

read from a html file and edit those lines python

i have this text file test.html
A B
C D
python file f = open('test.html') ans = "A" line =…
c5564200
  • 141
  • 1
  • 3
  • 9
1
vote
1 answer

Reading RTF Files line by line in C# WPF

I am working on a C# WPF tool, which shall read different text file types and analyze the file line by line. It works properly for example for a .asc text file: foreach (string line in File.ReadLines(myFile.asc)) { …
Julian
  • 185
  • 1
  • 15
1
vote
1 answer

Adding a string variable to the beginning of each string in a readlines structure

I have imported a file and used readlines to split each line into a string. I have another variable, "SubID", that I want to add to the beginning of each line. Here is the code I have tried. lines = file.readlines() [SubID] + lines