How take data for dictionary from txt file (Python)

I had stuck with one menu option in my work, is there is somebody who know how to convert a data from a txt file into dictionary format? The task is by menu option number 5 download data thet was made into txt file, and than, if the program was restart, and the data is… Read More How take data for dictionary from txt file (Python)

How to keep lines which contains specific string and remove other lines from .txt file?

How to keep lines which contains specific string and remove other lines from .txt file? Example: I want to keep the line which has word "hey" and remove others. test.txt file: first line second one heyy yo yo fourth line Code: keeplist = ["hey"] with open("test.txt") as f: for line in f: for word in… Read More How to keep lines which contains specific string and remove other lines from .txt file?

Can't read integer file

I’m trying to read data from a file that contains integers, but the Scanner doesn’t read anything from that file. I’ve tried to read the file from the Scanner : // switch() blablabla case POPULATION: try { while (sc.hasNextInt()) { this.listePops.add(sc.nextInt()); } } catch (Exception e) { System.err.println("~ERREUR~ : " + e.getMessage()); } break; And… Read More Can't read integer file

bash – Concatenate files in different subfolders into a single file and have each file name in the first column

I am trying to concatenate a few thousand files that are in different subfolders into a single file and also have the name of each concatenated file inserted as the first column so that I know which file each data row came from. Essentially starting with something like this: Folder1 file1.txt 123 010 … 456… Read More bash – Concatenate files in different subfolders into a single file and have each file name in the first column

How to optimize reading and cleaning file?

I have a file, which contains strings separated by spaces, tabs and carriage return: one two three four I’m trying to remove all spaces, tabs and carriage return: def txt_cleaning(fname): with open(fname) as f: new_txt = [] fname = f.readline().strip() new_txt += [line.split() for line in f.readlines()] return new_txt Output: [[‘one’], [‘two’], [], [‘three’], [],… Read More How to optimize reading and cleaning file?

Replacing all spaces with underscores in a text file with unix

Sorry if this is a repeat question; I am very green with unix. I have several (n = 12) text files that contain spaces in the first column that should all be changed to underscores. The files are of phylogeny ID and counts in different samples, see example below. phylodist all_Tg_3300056613 all_Tg_3300056890 all_Tg_3300057214 all_Tg_3300057270 all_Tg_3300057271… Read More Replacing all spaces with underscores in a text file with unix