OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Python azure blob storage - append to csv file only if row doesn't already exist

  • Thread starter Thread starter N1ckson
  • Start date Start date
N

N1ckson

Guest
Hi im trying to append to a csv file in an azure storage account from a python script, however originally i was overwriting this file but i realised that actually i needed some of the content to stay in the file but any new content to be put in there aswell but without all the old stuff thats already in there. An example would be like below:

local csv:

IDvalue
Onevalue1
Twovalue2

azure remote csv file:

IDvalue
Onevalue1
threevalue3

So with doing an overwrite here would mean i would lose the ID:three value:value3 here, and doing an append would mean i would duplicate the ID:one value:1



Heres the code i have so far:

Code:
from azure.storage.blob import ContainerClient

container_client = ContainerClient(account_url=url, container_name=name, credential=creds)

container_client.upload_blob(name=file, data=data, overwrite=True)

This is what i currently have setup, so the question would be about that overwrite part, do i need to maybe download the file first do the analysis then reupload using overwrite, or is there a better method ?
<p>Hi im trying to append to a csv file in an azure storage account from a python script, however originally i was overwriting this file but i realised that actually i needed some of the content to stay in the file but any new content to be put in there aswell but without all the old stuff thats already in there. An example would be like below:</p>
<p>local csv:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>value</th>
</tr>
</thead>
<tbody>
<tr>
<td>One</td>
<td>value1</td>
</tr>
<tr>
<td>Two</td>
<td>value2</td>
</tr>
</tbody>
</table>
</div>
<p>azure remote csv file:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>value</th>
</tr>
</thead>
<tbody>
<tr>
<td>One</td>
<td>value1</td>
</tr>
<tr>
<td>three</td>
<td>value3</td>
</tr>
</tbody>
</table>
</div>
<p>So with doing an overwrite here would mean i would <em>lose</em> the <code>ID:three value:value3</code> here, and doing an append would mean i would <em>duplicate</em> the <code>ID:one value:1</code></p>
<hr />
<p>Heres the code i have so far:</p>
<pre class="lang-py prettyprint-override"><code>
from azure.storage.blob import ContainerClient

container_client = ContainerClient(account_url=url, container_name=name, credential=creds)

container_client.upload_blob(name=file, data=data, overwrite=True)

</code></pre>
<p>This is what i currently have setup, so the question would be about that overwrite part, do i need to maybe download the file first do the analysis then reupload using overwrite, or is there a better method ?</p>
 
Top