file-io

Read a file, modify it, write it out, and then read it again – better options?

Read a file, modify it, write it out, and then read it again – better options? Question: I have a fixed width text file that I am trying to read in using pandas.read_fwf. As noted here, this method removes leading and trailing whitespace. In order to get around that, I’d like to replace every whitespace …

Total answers: 1

Split a binary file into 4-byte sequences (python)

Split a binary file into 4-byte sequences (python) Question: So, basically, I have a 256MB file which contains "int32" numbers written as 4-byte sequences, and I have to sort them into another file. The thing I struggle with the most is how I read the file into an array of 4-byte sequences. First I thought …

Total answers: 3

How to monitor existing filenames on a FTP server in Python

How to monitor existing filenames on a FTP server in Python Question: I need to monitor continuously an FTP server where images appear regularly (every second or so), copy them on my client PC and delete them. Deleting the images on the server is optional but I need to have this option, and I would …

Total answers: 1

what is the syntax for adding newline to this list expression

what is the syntax for adding newline to this list expression Question: So I am trying to write a few different values of this list to a few specific lines of this text file essentially replacing them. I got a tip on my last question to seperate the lines in this output I need to …

Total answers: 1

value error(line 7 for name, home) when using csv library in python CS50P file i/o

value error(line 7 for name, home) when using csv library in python CS50P file i/o Question: import csv students = [] with open("stu1.csv") as file: reader = csv.reader(file) for name, home in reader: students.append({"name": name}, {"home": home}) for student in sorted(students, key =lambda student:student["name"]): print(f"{student[‘name’]} is from {student[‘home’]}") stu1.csv contains below data Harry, Number, Pivet …

Total answers: 1

Regex pattern returns null for variable as pattern

Regex pattern returns null for variable as pattern Question: I am reading regex pattern from a .txt file and passing it as a variable and using it to search in a very big text file. However, variable passing in regex search didnt work. My code snippet is with open(r"C:Desktoplist_pattern.txt", "r") as file1: for pattern in …

Total answers: 2

Reading multiple txt files from multiple folders

Reading multiple txt files from multiple folders Question: I have 20 folders, each containing 50 txt files, I need to read all of them in order to compare the word counts of each folder. I know how to read multiple files in one folder, but it is slow, is there a more efficient way instead …

Total answers: 2

How to open a file in binary mode in google storage bucket from cloud function?

How to open a file in binary mode in google storage bucket from cloud function? Question: In my cloud function, I need to get a file in cloud storage and send the file to an API through HTTP POST request. I tried the following code: storage_client = storage.Client() bucket = storage_client.bucket(BUCKET_NAME) source_blob_name = "/compressed_data/file_to_send.7z" blob …

Total answers: 2

How do I get the child folder name of the path besides these methods?

How do I get the child folder name of the path besides these methods? Question: Of the given path like “level1/level2/level3/”, I’d like pass it through some operation and get the result like “level3/”. So I made two trials like these: TRIAL 1: After finding parent property within the Path object, I looked for something …

Total answers: 2