擅长:python、mysql、java
<p>编辑:将dict写入csv时,使用<code>io.StringIO()</code>作为类似文件的对象。然后调用<code>get_value()</code>,并将其作为数据参数传递给<code>requests.put()</code></p>
<p>有关更多详细信息,请参见此问题:<a href="https://stackoverflow.com/questions/9157314/how-do-i-write-data-into-csv-format-as-string-not-file">How do I write data into CSV format as string (not file)?</a></p>
<p>旧答案:</p>
<p>如果你的口述是这样的:</p>
<pre class="lang-py prettyprint-override"><code>my_dict = {'col1': 1, 'col2': 2}
</code></pre>
<p>然后您可以将其转换为csv格式,如下所示:</p>
<pre class="lang-py prettyprint-override"><code>csv_data = ','.join(list(my_dict.keys()))
csv_data += ','.join(list(my_dict.values()))
csv_data = csv_data.encode('utf8')
</code></pre>
<p>然后用<code>data=csv_data</code>执行<code>requests.put()</code>调用</p>