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,
Tag: file-io
Converting HTML to PDF works only when conversion command is given in separate file
I would like to generate invoices with a little Python program I’ve written. I want it to output the invoice first as an HTML file, then convert it to a PDF. Currently my code is creating the HTML doc as desired, but it is outputting a blank PDF file: When I run the code above, the HTML doc it puts
Python: Why opening an XFA pdf file takes longer than a txt file of same size?
I am currently developping some python code to extract data from 14 000 pdfs (7 Mb per pdf). They are dynamic XFAs made from Adobe LiveCycle Designer 11.0 so they contain streams that needs to be decoded later (so there are some non-ascii characters if it makes any difference). My problem is that calling open() on those files takes around
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?
Why does changing to `w+` mode for simultaneous reading from and writing to a file cause the read to fail?
I am writing code in Python which needs to register a user by RFID tag and write that record to a file. I managed to write a function which works perfectly fine: But I would like to optimise the code as much as possible and reduce the number of lines. Because of that, I decided to use w+ because it
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
ValueError : I/O operation on closed file
Here, p is a dictionary, w and c both are strings. When I try to write to the file it reports the error: Answer Indent correctly; your for statement should be inside the with block: Outside the with block, the file is closed.
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
write() versus writelines() and concatenated strings
So I’m learning Python. I am going through the lessons and ran into a problem where I had to condense a great many target.write() into a single write(), while having a “n” between each user input variable(the object of write()). I came up with: If I try to do: I get an error. But if I type: Then it works