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

Split each line in a file with a string in python

This is concerning Python: I’m trying to figure out how to read a file line by line, separate all content on any side of an “=“ sign, and store each object in the list (of each line) into separate variables which are stored in an instance of a…
-2
votes
3 answers

How can I make my text not surrounded by ['']?

I am using the readlines feature in python + discord.py however my value in my embed is surrounded by ['']. I'd like to remove it from my embed for obvious reasons snipeduser = open("snipes/snipeduser.txt", "r").readlines() …
DTOG
  • 123
  • 4
  • 10
-2
votes
1 answer

In the given code, whichever block i place first sequentially returns a result while the one i place [continued in desc]

[continuation]- second returns the result as zero, why and how do make both read functions work with the same file name? CODE: myfile=open(r'C:\Users\win8\Documents\Cs Record\trust.txt','r') **#number of lines in the…
Rayyan
  • 1
  • 1
-2
votes
2 answers

How to read through a file line by line and from each line selectively print the text based on the delimiters used

I have a file (application.txt) containing lines in the below format: mytvScreen|mytvScreen|Mi TV,Mí…
Kiran Das
  • 57
  • 6
-2
votes
1 answer

Csv readlines issue

I'm trying to readlines of a csv file file. The code to read the file in python with readlines and csv.reader works fine on windows but on Linux test server I am getting some issue maybe because of the \n at the end of each line. Is there some…
-2
votes
2 answers

python read lines in functional way

I need to write a program in a functional way. I have a text and I need to calculate a number of unique words, (for example: "word word, word word?" - has 3 different words, punctuation matters. I have a code: import sys import…
L.Bond
  • 37
  • 6
-2
votes
2 answers

Make python read 12 from file as 12 not 1 and 2

Trying to make a program that provides the price to different numbers of stages. In "tripss.txt",third line is the number 12, python interprets it as 1 and 2 instead and gives the price for each rather than the number as a whole, any way to fix it…
Vik
  • 1
  • 1
-2
votes
2 answers

Incorrect output while reading text file in Python

I need to read the first 30 lines of a file. with open(filename) as f: lines = f.readlines(30) print len(lines) 300 am I missing something?
Bob
  • 10,741
  • 27
  • 89
  • 143
-2
votes
2 answers

Python readlines() function writing [' and \n to file

So I have this code here which I am sure is trivial to my question as it is just question about readlines in general: lines = file_in.readlines() self.inputText.insert(1.0, lines,) If I were to read in a text file, it would write…
Senescence
  • 63
  • 1
  • 7
-3
votes
1 answer

Read two lines at a time from a txt file

The 1st piece of code shown below reads one line from a txt file It reads one line at a time but what I'd like to achive is making it read two lines at once. I tried to call the function twice, but all what it does is it reads the same line and…
-3
votes
2 answers

Read lines and make a dictionary

The original txt file composed of multiple lines say in the following format: Q1: Number of responses: 100 Answers: A. Python B. Java C. JavaScript Q2: ... What I did: import re file = 'file.txt' text = open(file, "r",…
-3
votes
1 answer

Readlines is only reading the first line in my text file

im trying to convert a program that takes the users string input and defines how many lowercase, uppercase, digits, and characters the string has. Into a program that reads a text file and outputs lower/uppercase/digits/and characters. I have most…
Adrian
  • 1
-3
votes
1 answer

Why is the output of readline() blank in a non-empty text file?

I am running python 3.7 in Wing IDE as an administrator. The python file is in the same folder (Documents) as the textdoc file. This is the python code I have: file = open("textdoc.txt", "r") print(file.readlines()) file.close() This is the…
Clock
  • 35
  • 2
-3
votes
1 answer

How to put a file.txt into more than one list in python

I am trying to put my file.txt into a list and then each index into different lists while all the lists remain in the initial list. I have been able to add it into a single list so far. Here's my code: with open("evenements.txt", "r",…
Oxynor
  • 41
  • 6
-4
votes
1 answer

Reverse block of text every x lines in python

Im sure this is a simple readlines solution. I have spent some time trying to solve it without success. I have a block of text that reads: "This is the text 1" 0.0 2.0 2.0 2.0 0.0 0.0 4.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0…
ZachW
  • 48
  • 6
1 2 3
33
34