Python与C中的FileStream等价什么?

2024-10-01 04:46:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Python中复制这段代码,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中的FileStreamis是什么等价物,所以我无法翻译代码。在


Tags: 文件csv代码文本编码newbufferwrite
1条回答
网友
1楼 · 发布于 2024-10-01 04:46:33

与C的FileStream等价的是Python的file对象。它们都处理读写文件,并且不会对读/写的数据进行任何重大操作。(我不确定什么是“编码下载文本流”,但两种语言的文件编写器都不会自行解码它。)

(在文本模式下打开时,Python的file对象将规范化行尾,但仅此而已。)

相关问题 更多 >