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

Using python read floats from a file and store only the decimals

So I am in a operating system class and my assignment is to harvest bits from a geiger counter. Every time the geiger counter reports something I receive a timestamp i.e. 1522187398.44 1522187408.17 there is one timestamp per line. I currently have…
GenCrash10
  • 9
  • 1
  • 5
-1
votes
1 answer

Using readLines for multiple files in R

My question is similar to the topic, I would like to load two files at once. I know I can use the function list.files. However, I do not know how to apply it correctly so that my program will work. I would also like to ask how can I make two frames…
Elia
  • 53
  • 7
-1
votes
1 answer

creating single line from mulitplelines from huge text file in python or others based on id

I have a very large text file(20GB) which as rows like this, 1 Some text 1 More text 2 Text 2 Follow up text .. .. n I want to covert file to like this: 1, sometext, more text 2, text , followup text How can i do it python. I can not keep entire…
user5236897
-1
votes
2 answers

How to readlines without having the \n at the end? (python)

As I was finishing off a game I made, I made a save button that saves to a file. When the game opens, it will then read the file and save those lines as variables. I do so, but then I see that it needs to be an integer, so I use int(). But then it…
Anonymous
  • 355
  • 2
  • 14
-1
votes
2 answers

How to pull certain information from excel spreadsheet?

I am extremely new to python and want to learn how to pull certain elements from a data sheet. For example: How many attributes/categories the data has? How many missing values the data has? How many columns the data has? The frequency of an…
-1
votes
6 answers

Skip one line - python open with

How I can skip first header line? I have headers duplicated later in the code, so I can eliminate them by if not l.startswith('MANDT') but first header I want to keep. How I need to modify the code? keep ->…
user2433705
  • 141
  • 1
  • 10
-1
votes
3 answers

Python strip() and readlines()

I have a code that I am trying to run which will compare a value from a csv file to a threshold that I have set within the py file. My csv file has an output similar to below, but with 1030 lines -46.62 -47.42 -47.36 -47.27 -47.36 …
user7524882
  • 1
  • 1
  • 5
-1
votes
1 answer

Read text from file given specific indexes

I have a file with some text content. e.g. file name = RandomText.txt string content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"; I want to be able to extract content given specific indexes e.g. get text from index 5 to index…
J. Doe
  • 1
  • 2
-1
votes
1 answer

vb.net - r.peek()>=0 line = r.readline()

I am using vb.net to read a text file and see if a record matched, and to pick out that record and write it to excel. However with the peek loop it reads the file until the end of it. I have 2 peek loop - the outer peek loop looks for the item, the…
Johnseito
  • 315
  • 1
  • 9
  • 24
-1
votes
1 answer

python 3.x readlines()

After a pause I've currently started to work with python again but right at the start I encountered an annoying (and at least for me not solvable...) problem. I want to open a normal .txt file with tabular content so I can iterate over specific…
-1
votes
1 answer

How to display "..." (3 dots) if a sentence takes more than 2 lines in php?

I looked all over online for this but could not find. I only found for those that use string longer than a specific number defined but I need to display those dots if the sentence takes more than 2 lines. For example, sentence below is long : The…
-1
votes
2 answers

Writing to and reading plain text files with writelines() and readlines()

I understand what these functions do, but what would be the practical use of reading/writing some as a list, and what is the use of writing a list to a file, if you could just use write() and then later use readlines() to view it as a list?
Justin
  • 547
  • 3
  • 7
  • 15
-1
votes
1 answer

Need help input text file via ruby into hash than selecting same vaule from hash

My text file data looks like this:(protein-protein interaction data) transcription_factor protein Myc Rilpl1 Mycn Rilpl1 Mycn "Wdhd1,Socs4" Sox2 Rilpl1 Sox2 "Wdhd1,Socs4" Nanog "Wdhd1,Socs4" I want it to look like this:( To see each protein has…
Michael
  • 65
  • 1
  • 7
-1
votes
1 answer

Python 2.7: Convert one line into lines of 260 characters and remove all character before '_' in each line

I must convert infile into lines of 260 characters and than remove all the content before (including the character) '_' I have been looking around for hours now and found a way to convert to 260 characters. lines = infile.readlines() [line[i:i+n]…
user2343368
  • 403
  • 1
  • 4
  • 6
-2
votes
7 answers

How write python to Read the first two lines from a text file named "file1.txt" Write the two lines read from "file1.txt" to a new file "file2.txt"

Read the first two lines from a text file named "file1.txt" Write the two lines read from "file1.txt" to a new file "file2.txt"