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

Cannot authenticate to SSH server with correct credentials (username and password) read from a local file

I'm making a small program that connects into an SSH server, testing multiple usernames and passwords that are inside a .txt file. The problem I'm having is when it get to the correct username and password it doesn't connect, or at least my if…
Vitor
  • 43
  • 2
  • 7
3
votes
3 answers

Python: How to properly use readline() and readlines()

I've build a Python script to randomly create sentences using data from the Princeton English Wordnet, following diagrams provided by Gödel, Escher, Bach. Calling python GEB.py produces a list of nonsensical sentences in English, such as: resurgent…
reaction hashs
  • 51
  • 1
  • 1
  • 5
3
votes
1 answer

aws lambda read line by line and write to file

how can I write my results from a file processing step with AWS lambda and python back to a file? I'm reading a file from S3 and looking for a special expressing in each line. If this expression is included, I manipulate the line. As lambda is not…
3
votes
1 answer

Why does '\x01\x1A' (Start-of-Header and Substitute control characters) in a textfile line stop a for-loop prematurely?

I'm using Python 2.7.15, Windows 7 Context I wrote a script to read and tokenize each line of a FileZilla log file (specifications here) for the IP address of the host that initiated the connection to the FileZilla server. I'm having trouble parsing…
Minh T.
  • 33
  • 5
3
votes
1 answer

Apache Common FileUtils readLines method ambiguous call

I stumbled upon this problem when trying to play around with Apache commons IO third party API with Android Studio. Basically when I try to call the FileUtils.readLines() method, there are 3 options: readLines(File file) >>>> DEPRECATED…
blue2609
  • 841
  • 2
  • 10
  • 25
3
votes
1 answer

Parse complex text file in R

I am looking to parse a text file in R to be loaded as a data.frame. I have a long text file with fixed width data, seperated by sections (ID) and subsections (SUB). The length of each section is variable. I'm looking to create two data frames, one…
user2325155
  • 147
  • 2
  • 10
3
votes
1 answer

How to I read several lines in a file faster using python?

As of now I use the following python code: file = open(filePath, "r") lines=file.readlines() file.close() Say my file has several lines (10,000 or more), then my program becomes slow if I do this for more than one file. Is there a way to speed this…
Sandhya Jha
  • 356
  • 1
  • 7
  • 18
3
votes
1 answer

How to create and write to a textiowrapper and readlines

So I am trying to create a text io wrapper that I can then use readlines() from for a unittest. Here is my attempt, but when I run it the readlines() returns nothing: output = io.BytesIO() wrapper = io.TextIOWrapper( output, encoding='cp1252', …
EliSquared
  • 1,409
  • 5
  • 20
  • 44
3
votes
4 answers

Print specific lines of multiple files in Python

I have 30 text files of 30 lines each. For some reason, I need to write a script that opens file 1, prints line 1 of file 1, closes it, opens file 2, prints line 2 of file 2, closes it, and so on. I tried this: import glob files =…
3
votes
4 answers

Converting text files to pandas dataframe

I have .TX0 file (some sort of csv txt file) and have converted this to a .txt file via python .readlines(), open(filename, 'w') etc method. I have this new saved txt file but when i try to convert it to a dataframe it's giving me only one column.…
Joey
  • 914
  • 4
  • 16
  • 37
3
votes
1 answer

Python pandas : dataframe read rows (readlines)

I have a dataframe that was produced by pandas, for example: d = {'one':[1,1],'two':[2,2], 'three':[3,3]} i = ['a','b','c'] df = pd.DataFrame(data = d, index = i) df one two three a 1 2 3 b 1 2 3 c 1 2 …
Yang May
  • 453
  • 1
  • 5
  • 10
3
votes
3 answers

Importing a text file gives error

I have a text file that has the following data: 5298 10036 4 360 8 6128 11947 2 385 7 9472 18930 0 233 4 5056 9790 1 293 6 I read this file using the following code: file1 = open("test.txt","r") lines =…
Abhinav Kumar
  • 1,613
  • 5
  • 20
  • 33
3
votes
3 answers

Simple login function in Python

def login(): user = raw_input("Username: ") passw = raw_input("Password: ") f = open("users.txt", "r") for line in f.readlines(): us, pw = line.strip().split("|") if (user in us) and (passw in pw): …
blazePascal
  • 35
  • 1
  • 1
  • 4
3
votes
5 answers

How to Iterate over readlines() in python

I am trying to add lines from a txt file to a python list for iteration, and the script wants to print every line and return an error. I'm using the readlines() function, but when I use list.remove(lines), it returns an error: File "quotes.py",…
joshlsullivan
  • 1,375
  • 2
  • 14
  • 21
3
votes
2 answers

Python restrict newline characters for readlines()

I am trying to split a text which uses a mix of new line characters LF, CRLF and NEL. I need the best method to exclude NEL character out of the scene. Is there an option to instruct readlines() to exlude NEL while splitting lines? I may be able to…
Gaudha
  • 35
  • 1
  • 6