Reading and Writing special characters in Python

Advertisements Python ver. 3.11.5 on Windows 10 I have a directory filled with .gz text archives. To scan these archives, I use the following python code: with gzip.open(logDir+"\\"+fileName, mode="rb") as archive: for filename in archive: print(filename.decode().strip()) All used to work, however, the new system adds lines similar to this: :§f Press [§bJ§f] Python gives me… Read More Reading and Writing special characters in Python

select specific rows in text file to read into two separate columns in a pandas dataframe

Advertisements I have a text file like the following 2022-mary [‘apple’, ‘oranges’, ‘pineapple’] 2022-cindy [‘mango’, ‘banana’, ‘berry’] 2022-andrew [‘coconut’, ‘cabbage’] I would like to produce a pandas dataframe with 2 columns from the text file above that looks like this user fruits 0 2022-mary [‘apple’, ‘oranges’, ‘pineapple’] 1 2022-cindy [‘mango’, ‘banana’, ‘berry’] 2 2022-andrew [‘coconut’,… Read More select specific rows in text file to read into two separate columns in a pandas dataframe

Read text files with multiple lists with spacings and commas exist between elements in the lists into pandas dataframe

Advertisements I have a text file called tropical.txt that have multiple lists and each list is separated by a new line. Notice the comma is surrounded by spaces. space here and space here | | [‘papaya’ , ‘mangosteen’ , ‘banana’] [] [‘coconut’ , ‘mango’] [‘mangosteen’ , ‘papaya’] I tried the following code import pandas as… Read More Read text files with multiple lists with spacings and commas exist between elements in the lists into pandas dataframe

Bad file descriptor fgets

Advertisements I’m trying to create a file to send information to another process. But when I reach the send_file function, I get –>Error in fgets():: Bad file descriptor. Can someone help me address this matter, please? I’m stuck. #include <stdlib.h> #include <stdio.h> void send_file(FILE *fp, int sockfd){ char data[SIZE] = {0}; if (fgets(data, SIZE, fp)… Read More Bad file descriptor fgets