I want to upload a text string as a file via FTP.
import ftplib
from io import StringIO
file = StringIO()
file.write("aaa")
file.seek(0)
with ftplib.FTP() as ftp:
ftp.connect("192.168.1.104", 2121)
ftp.login("ftp", "ftp123")
…
I'm trying to decide on the best internal interface to use in my code, specifically around how to handle file contents. Really, the file contents are just binary data, so bytes is sufficient to represent them.
I'm storing files in different remote…
I can't understand the difference of these two BytesIO objects.
If i do this :
f = open('decoder/logs/testfile.txt', 'rb')
file = io.BytesIO(f.read())
decode(file,0)
then in decode method this works :
for line in islice(file, lines, None):
But…
Create a zip file from a generator in Python? describes a solution for writing a .zip to disk from a bunch of files.
I have a similar problem in the opposite direction. I am being given a generator:
stream = attachment.iter_bytes()
print…
I'm working with Django and need to read the sheets and cells of an uploaded xlsx file. It should be possible with xlrd but because the file has to stay in memory and may not be saved to a location I'm not sure how to continue.
The start point in…
I want to give xlsx on request. With using BytesIO and xlsxwriter I create a file.
Using the code below, I can download an empty(!) .txt file:
@router.get("/payments/xlsx", response_description='xlsx')
async def payments():
"""sss"""
output…
What I am trying to do is basically:
Get PDF from URL
Modify it via pdfrw
Store it in memory as
a BytesIO obj
Upload it into a Django FileField via
Model.objects.create(form=pdf_file, name="Some name")
My issue is that when the create() method…
I am using pandas library to store excel into bytesIO memory. Later, I am storing this bytesIO object into SQL Server as below-
df = pandas.DataFrame(data1, columns=['col1', 'col2', 'col3'])
output = BytesIO()
writer =…
I am attempting to pull a file from AWS S3, using Boto3, directly into a BytesIO object. This will eventually be used to manipulate the downloaded data but for now I'm just trying to give that file directly to a user via Flask. As I understand…
See update at bottom - question slightly changed
I'm trying to download a file from s3 to a file-like object using boto3's .download_fileobj method, however when I try to inspect the downloaded bytestream, it's empty. I'm not sure what I'm doing…
I have found that there are a lot of similarities between both modules in the area of creating temp files using io.BytesIO() or io.StringIo() and tempfile.TemporaryFile()
What is the purpose of each one ?
Context:
I currently have a program which loads a set of plugins from their file paths (in a mapped network drive) using the method shown in another SO thread. These plugins are designed to be rolling release, which means I need constant access to…
Imagine that I am manipulating a shapefile in geopandas. I then want to load it using another library (like networkx) but since my file is large I dont want to have to save and reload it. Is there a way I can save it in memory? I imagine it would…
I'm having trouble writing a .tar.gz file in Python from a BytesIO Object. Writing just a plain tarfile works great, but if I change the write mode to be .tar.gz (or bz, or xz) it doesn't produce a valid tar file.
I've made a stripped down version…
I am trying to use a context manager for a BytesIO stream while creating multiple zip files. I can find no way to "reset" the BytesIO object after the first zip file is written, so I can use the same BytesIO object to create the next zip file. I…