Skip to content
Advertisement

Tag: file-io

Output of split is not what I was expecting

I’m just learning python, and I’m having some problems reading a .txt file that I created. My objective: I have a txt file with a list of strings. I’m trying to read, process it and save every letter into a new list. example2.txt file: [one, two, THREE, one, two, ten, eight,cat, dog, bird, fish] [Alonso, Alicia, Bob, Lynn] , [red,

How to save Python 1D, 2D or 3D NumpPy array into MATLAB .mat

Python’s SciPy package has a function that saves Python variable into MATLAB’s .mat file https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.savemat.html However, the documentation lacks examples, and I don’t know what is the dictionary of variables it wants as an input. Say I have a 2D NumPy array A and a 3D NumPy array B, how do I save them into a .mat file called my_arrays.mat?

Loading Matlab files into Python

I am attempting to understand the difference between loading a data file into Python and into Matlab in order to translate some code. I have a line of code that goes: When I run the code in Matlab I know that the data is in workspace. There is a 224×501 double called datalib and a 501×29 double called names. The

watchdog monitoring file for changes

I have a need to watch a log file for changes. After looking through stackoverflow questions, I see people recommending watchdog. So I’m trying to test, and am not sure where to add the code for when files change: Where do I add the “got it” — in the while loop if the files have been added/changed? Answer Instead of

How do I concatenate text files in Python?

I have a list of 20 file names, like [‘file1.txt’, ‘file2.txt’, …]. I want to write a Python script to concatenate these files into a new file. I could open each file by f = open(…), read line by line by calling f.readline(), and write each line into that new file. It doesn’t seem very “elegant” to me, especially the

Advertisement