【发布时间】:2017-01-24 23:48:48
【问题描述】:
我正在尝试在 Python 中复制这段代码,该代码采用 base64 编码的文本流并将其逐字节写入 csv 文件:
using (FileStream localFileStream = new FileStream(destinationPath, FileMode.Create, FileAccess.Write))
{
using (Stream remoteStream = client.DownloadFile(jobId))
{
while (!endOfStream)
{
bytesRead = remoteStream.Read(buffer, 0, buffer.Length);
if (bytesRead > 0)
{
localFileStream.Write(buffer, 0, bytesRead);
totalBytes += bytesRead;
}
else
{
endOfStream = true;
}
}
}
}
不幸的是,我不知道 Python 中 FileStream 的等价物是什么,所以我无法翻译代码。
【问题讨论】:
-
这个问题你已经问过一次了;修改您现有的问题,而不是问另一个问题。
-
我想我会删除第一个问题,这个更具体,为混淆道歉
-
您的问题似乎归结为“如何在 Python 中编写文件”。 pythonforbeginners.com/files/…
-
另外,这个问题与您想要做的事情非常相似:从网络流中读取,写入文件。 stackoverflow.com/questions/39683734/…(问题中的代码示例,不是答案。)