text-files

How to delete lines which contains only numbers in python?

How to delete lines which contains only numbers in python? Question: I have a large text file in Python. Firstly, I want to read the text then, delete lines which have only numbers. Then, I open a new text file and write with my changes. If the line contains numbers and strings, I want to …

Total answers: 2

Selecting all lines/strings that fall between pattern in text file

Selecting all lines/strings that fall between pattern in text file Question: Given a text file that looks like this when loaded: >rice1 1ALBRGHAER NNNNNNNNNNNNNNNNNNNNN NNNNNNNNNNNNNNNNNNNNN >peanuts2 2LAEKaq SSSSSSSSSSS >OIL3 3hkasUGSV ppppppppppppppppppppp ppppppppppppppppppppp How can I extract all lines that fall between lines that contain ‘>’ and the last lines where there is no ending ‘>’ …

Total answers: 2

How to extract specific lines from a text file and then from these extracted line, extract the values between parantheses and put them in another file

How to extract specific lines from a text file and then from these extracted line, extract the values between parantheses and put them in another file Question: infile = open(‘results1’, ‘r’) lines = infile.readlines() import re for line in lines: if re.match("track: 1,", line): print(line) question solved by using python regex below Asked By: cosmicdust …

Total answers: 2

How to return the line number of a line being read from a text file?

How to return the line number of a line being read from a text file? Question: I have a text file (my_file.txt) as follows: Game of Thrones Friends Suits Hospital Playlist From this file, I need to choose a random line & return it along with the line number. For returning a random line, I …

Total answers: 2

Python3: how to count columns in an external file

Python3: how to count columns in an external file Question: I am trying to count the number of columns in external files. Here is an example of a file, data.dat. Please note that it is not a CSV file. The whitespace is made up of spaces. Each file may have a different number of spaces …

Total answers: 1

How can I assign the contents of a .txt file to a string variable in Python?

How can I assign the contents of a .txt file to a string variable in Python? Question: I have a text file path stored in a variable called settings_data_path and I want to take whatever is in that text file and put it into a string variable, in this instance, limited_n_ints . So I opened …

Total answers: 1