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

Cant convert to different data types

I am trying to run a .txt file with raw data into my code but I keep getting a value error. It was working before, but now I am getting this error: ValueError: could not convert string to float: '.' Here is my file with the raw…
Tristan
  • 1
  • 2
-1
votes
1 answer

How to take user input as part of program execution in shell?

I wrote a simple script that reads text from a file and writes it to a new file. It currently functions by prompting the user to enter the name of the file, but I would like to save time and include that as part of program execution. lattice =…
carcinogenic
  • 169
  • 1
  • 2
  • 10
-1
votes
1 answer

How can I remove the space after qlineedit get text?

I am programming an app with python 3.8.3 and pyQt5. Here's a part of my code: def logind(self): datas=open('NeveshtarUsers.txt', 'r') data=datas.readlines() print(data) n=self.user.text() print(n,'\n') …
F. Basiri
  • 1
  • 2
-1
votes
2 answers

how to use readlines()

Here on running the following code I am getting an error as below. Can anyone please help me with this. import urllib import requests url = "https://www.sec.gov/Archives/edgar/data/1800/000104746918000856/0001047469-18-000856.txt" page =…
Berlin
  • 7
  • 4
-1
votes
4 answers

How do I read certain 4 digits in a file and move to another line and do the same and so on

So I have this problem I need to solve. I have a file that goes something…
cosman
  • 23
  • 5
-1
votes
3 answers

Reading n lines from end of text file using python

I am trying to write a programme to read and print the last n lines of a text file in python. My text file has 74 lines. I wrote a function like below to read the last n lines. s=74 //Got this using another function, after enumerating the text…
zorbamj
  • 11
  • 9
-1
votes
3 answers

Help me speed-up this code - Python

Guys i am writing this program that goes through list of tweets and returns words which was use the most. I want to make it faster but I wonder if you can help point out some problems or areas which i can improve the speed. thanks see code…
-1
votes
2 answers

Python reading number of lines

I just wanted to query the best way to read the lines of a text file back into a dict or class object. The data I've written to a text file is quite crude, so I'm sure there may be better ways of formatting. Essentially the data looks like this (--…
TeXaS_pEtE
  • 59
  • 4
-1
votes
1 answer

Trying to stepwise iterate through 2 files in python

I am trying to merge two LARGE input files together into 1 output, sorting as I go. ## Above I counted the number of lines in each table print("Processing Table Lines: table 1 has " + str(count1) + " and table 2 has " + str(count2) ) newLine,…
bnp0005
  • 199
  • 1
  • 3
  • 11
-1
votes
1 answer

how to make python print the whole file instead of just the single line

I have a .csv file that has just one column of numbers and I want to read each number in the column and print it in the console like this: 1 2 3 4 here is the code that I have used: file_reference2 = open("file1.csv", "r") read_lines1 =…
Connel Chen
  • 69
  • 1
  • 1
-1
votes
1 answer

VB.NET - Replace column value in text file that is space delimited

I am trying to run a vb.net script from SSIS to perform the following in a space delimited text; Loop through all files in directory (I've already coded this using .GetFiles) Within each text file loop through each line within the…
rando513
  • 11
  • 3
-1
votes
1 answer

readlines() not working when used on a CSV file

So have a "file.csv" and I want to extract some data from it using Python. The problem for me is that the lines are formatted not in standard csv format, but instead a line looks like this: ;a_value=value;b_value=value; So my idea was to use…
-1
votes
1 answer

readlines from iterating through an array and writelines to a new file

bad_list is an array that is returned from a different function, returns the line numbers of rows that are problematic and need to be looked at more closely e.g. array([ 1, 3, 4, 27, 50, 99], dtype=int64) The idea is to read test.txt, and make…
Jeremy Wu
  • 17
  • 5
-1
votes
2 answers

using readlines() and count() in a "for" loop?

In Codio, there is a challenge to take a file, search for the number of times a string appears in it, then print that number. I was able to get the result using some suggestions, but I am still unclear on a few things. The main question is, at what…
Toph Hughes
  • 101
  • 1
  • 10
-1
votes
1 answer

How to stop reading lines from a XML file when a certain string is reached using python language

I am currently working on this code that creates a summary from an XML input file. However, the summary picks up irrelevant information that is towards the end of the file. For instance, I want to read all of the lines of the XML file except when it…
user9608799
  • 31
  • 1
  • 8