Upload CSV file into Microsoft Azure storage account using python

2024/11/15 21:06:43

I am trying to upload a .csv file into Microsoft Azure storage account using python. I have found C-sharp code to write a data to blob storage. But, I don't know C# language. I need to upload .csv file using python.

Is there any example of python to upload contents of CSV file to Azure storage?

Answer

I found the solution using this reference link. My following code perfectly work for uploading and downloading .csv file.

#!/usr/bin/env pythonfrom azure.storage.blob import BlockBlobService
from azure.storage.blob import ContentSettingsblock_blob_service = BlockBlobService(account_name='<myaccount>', account_key='mykey')
block_blob_service.create_container('mycontainer')#Upload the CSV file to Azure cloud
block_blob_service.create_blob_from_path('mycontainer','myblockblob.csv','test.csv',content_settings=ContentSettings(content_type='application/CSV'))# Check the list of blob
generator = block_blob_service.list_blobs('mycontainer')
for blob in generator:print(blob.name)# Download the CSV file From Azure storage
block_blob_service.get_blob_to_path('mycontainer', 'myblockblob.csv', 'out-test.csv')
https://en.xdnf.cn/q/71709.html

Related Q&A

GeoDjango: How can I get the distance between two points?

My Profile model has this field:location = models.PointField(geography=True, dim=2, srid=4326)Id like to calculate the distance between the two of these locations (taking into account that the Earth is…

Reading direct access binary file format in Python

Background:A binary file is read on a Linux machine using the following Fortran code:parameter(nx=720, ny=360, nday=365) c dimension tmax(nx,ny,nday),nmax(nx,ny,nday)dimension tmin(nx,ny,nday),nmin(nx,…

Fabric/Python: AttributeError: NoneType object has no attribute partition

Have the following function in fabric for adding user accounts.~/scripts #fab -lPython source codeAvailable commands:OS_TYPEadduser_createcmd Create command line for adding useradduser_getinfo Prom…

Python object @property

Im trying to create a point class which defines a property called "coordinate". However, its not behaving like Id expect and I cant figure out why. class Point:def __init__(self, coord=None…

Tkinter - Inserting text into canvas windows

I have a Tkinter canvas populated with text and canvas windows, or widgets, created using the create_text and create_window methods. The widgets I place on the canvas are text widgets, and I want to in…

How to run nosetests without showing of my matplotlibs graph?

I try to run my test without any messages displaying from my main program. I only want verbose messages from nosetests to display.For example: nosetests -v --nologcaptureAll of my printout messages fro…

Variable name to string in Python

I have written some code in Python and I would like to save some of the variables into files having the name of the variable. The following code:variableName1 = 3.14 variableName2 = 1.09 save_variable_…

In Python, how to print FULL ISO 8601 timestamp, including current timezone

I need to print the FULL local date/time in ISO 8601 format, including the local timezone info, eg:2007-04-05T12:30:00.0000-02:00I can use datetime.isoformat() to print it, if I have the right tzinfo o…

TextVariable not working

I am trying to get the Text out of an Entry widget in Tkinter. It works with Entry1.get(), but it does not work using textvariableWhat am I doing wrong ? from Tkinter import * master = Tk() v = String…

Is there a Python module to get next runtime from a crontab-style time definition?

Im writing a dashboard application and I need a way to figure out how long an item is "valid", i.e. when should it have been superseded by a new value (its possible to have an error such that…