temporary-files

Reading binary file using numpy in Streamlit

Reading binary file using numpy in Streamlit Question: I have the following code snippet that works perfectly well in python, however, I am trying to use streamlit to upload the binary files, but I can’t seem to make it work. Here is the working code in python: def read_bin(): dt = np.dtype([(‘col1′,’d’),(‘col2′,’d’),(‘col3′,’d’),(‘col4′,’d’)]) data = np.fromfile(‘Files/Bin …

Total answers: 1

How to put data into a tempfile and post as CSV on SFTP

How to put data into a tempfile and post as CSV on SFTP Question: Goal is Create a temporary SCP file filled with data and upload it to an sftp. The data to fill is TheList and is from class list. What I am able to achieve Create the connection to the SFTP Push a …

Total answers: 1

Getting code from a .txt on a website and pasting it in a tempfile PYTHON

Getting code from a .txt on a website and pasting it in a tempfile PYTHON Question: I was trying to make a script that gets a .txt from a websites, pastes the code into a python executable temp file but its not working. Here is the code: from urllib.request import urlopen as urlopen import os …

Total answers: 2

How to test image upload on Django Rest Framework

How to test image upload on Django Rest Framework Question: i’m on a struggle. The problem is with the unit testing ("test.py"), and i figured out how to upload images with tempfile and PIL, but those temporary images never get deleted. I think about making a temporary dir and then, with os.remove, delete that temp_dir, …

Total answers: 3

python tempfile | NamedTemporaryFile can't use generated tempfile

python tempfile | NamedTemporaryFile can't use generated tempfile Question: I would like to load the temp file to make changes or just be able to upload it somewhere, When I try to do so – It throws an error as shown below I have set the permission to w+ – which should ideally allow me …

Total answers: 2

How to save UploadFile in FastAPI

How to save UploadFile in FastAPI Question: I accept the file via POST. When I save it locally, I can read the content using file.read (), but the name via file.name incorrect(16) is displayed. When I try to find it by this name, I get an error. What might be the problem? My code: @router.post( …

Total answers: 7

Is it possible to get the path of a tempfile in Python 3

Is it possible to get the path of a tempfile in Python 3 Question: I was wondering if it was possible to get the file path of a temporary file made using the tempfile library. Basically, I’m trying to make a function that intakes some data, and generates a temporary csv file based off of …

Total answers: 4

Why doesn't tempfile.SpooledTemporaryFile implement readable, writable, seekable?

Why doesn't tempfile.SpooledTemporaryFile implement readable, writable, seekable? Question: In Python 3.6.1, I’ve tried wrapping a tempfile.SpooledTemporaryFile in an io.TextIOWrapper: with tempfile.SpooledTemporaryFile() as tfh: do_some_download(tfh) tfh.seek(0) wrapper = io.TextIOWrapper(tfh, encoding=’utf-8′) yield from do_some_text_formatting(wrapper) The line wrapper = io.TextIOWrapper(tfh, encoding=’utf-8′) gives me an error: AttributeError: ‘SpooledTemporaryFile’ object has no attribute ‘readable’ If I create a simple class …

Total answers: 2

Python – writing and reading from a temporary file

Python – writing and reading from a temporary file Question: I am trying to create a temporary file that I write in some lines from another file and then make some objects from the data. I am not sure how to find and open the temp file so I can read it. My code: with …

Total answers: 4

Empty/blank result file when using shutil to copy a tempfile

Empty/blank result file when using shutil to copy a tempfile Question: import tempfile import shutil tmp_f = tempfile.NamedTemporaryFile(delete=False) tmp_f.write("hello world") shutil.copy(tmp_f.name, "/etc/exports") When I read /etc/exports, it is a completely empty file. what is wrong? Asked By: pepero || Source Answers: You need to close the file: tmp_f.write(“hello world”) tmp_f.close() Answered By: j4hangir In addition …

Total answers: 2