readfile

How to convert many txt files to json data in python?

How to convert many txt files to json data in python? Question: I have many txt files, and i need to megre all them in one file or variable, and i want to do them readable. Example one file content: [{‘id’: ‘dc0920dc-3fc4-4be6-be96-26d896623469’, ‘courseId’: ’00e6f05f-a395-4ad0-b10c-e5ff575d26b7′, ‘description’: ‘Если цена отклоняется от рыночной в несколько раз, это может …

Total answers: 1

How do I print lines from a file in python after and before a match?

How do I print lines from a file in python after and before a match? Question: I would like to print some specific lines from a file, only those lines that come after a certain word appears on a line (‘Ingredients:’) and before another word appears (‘Instructions:’). The file is a list of recipes and …

Total answers: 3

Line extracted from text not matching the content of the text array

Line extracted from text not matching the content of the text array Question: I have this block of code: def removal(i): with open(r"D:LargecodefileCustomer.txt", "r") as f: lines = f.readlines() h,j = i-2,i-1 data1, data2 = lines[h],lines[j] print(‘data is ‘,data1,’and’,data2) print(‘line is ‘,lines) with open(r"D:LargecodefileCustomer.txt", "w") as f: for line in lines: if line.strip(‘n’) != data1 …

Total answers: 2

How to read a txt file from the last of its lines to the first of its lines?

How to read a txt file from the last of its lines to the first of its lines? Question: I need to read this file with a python code but in an inverted way to obtain the output that I will indicate below. sp_ordinal_numbers_info.txt 1: Primero 2: Segundo 3: Tercero 4: Cuarto 5: Quinto 10: …

Total answers: 2

I have a list splitting problem in Python

I have a list splitting problem in Python Question: I’m reading a file into a list. Now I want, that every after coma which I have in my list, there should be a new index. By now, everything is placed in index 0. relevanted Code: def add_playlist(): playlist_file_new =filedialog.askopenfilename(initialdir=f’C:/Users/{Playlist.username}/Music’,filetypes=[(‘Playlistdateien’,’.txt’)]) with open (playlist_file_new,’r’) as filenew: filenew_content …

Total answers: 5

how to read this netCDF file in python?

how to read this netCDF file in python? Question: I have this NetCDF file. it has 2 groups in it! I want to select one group and get the desired variable. I tried this in multiple ways but I failed. I could use simply print(ncfile.variables) but it’s not working! the file structure looks like this, …

Total answers: 1

Using endswith to read list of files doesn't find extension in list

Using endswith to read list of files doesn't find extension in list Question: I am trying to get my python script to read a text file with a list of file names with extensions and print out when it finds a particular extension (.txt files to be exact). It reads the file and goes through …

Total answers: 3

Open text file as input to textblob

Open text file as input to textblob Question: I am trying to use textBlob with a text file input. All examples I found online were of input in this sense: wiki = TextBlob(“Python is a high-level, general-purpose programming language.”) wiki.tage I tried this: from textblob import TextBlob file=open(“1.txt”); t=file.read(); print(type(t)) bobo = TextBlob(t) bobo.tags The …

Total answers: 3

difference between readlines() and split() [python]

difference between readlines() and split() [python] Question: imagine we have a file = open(“filetext.txt”, ‘r’) what is the difference between the split() method and the readlines() method It seems that both split each line and put it as a string in a list. so what makes them different ? for line in file: values = …

Total answers: 3

Skip rows during csv import pandas

Skip rows during csv import pandas Question: I’m trying to import a .csv file using pandas.read_csv(), however, I don’t want to import the 2nd row of the data file (the row with index = 1 for 0-indexing). I can’t see how not to import it because the arguments used with the command seem ambiguous: From …

Total answers: 6