久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Python 2.x - 將二進制輸出寫入標準輸出?

Python 2.x - Write binary output to stdout?(Python 2.x - 將二進制輸出寫入標準輸出?)
本文介紹了Python 2.x - 將二進制輸出寫入標準輸出?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

有沒有辦法在 Python 2.x 中將二進制輸出寫入 sys.stdout?在 Python 3.x 中,您可以只使用 sys.stdout.buffer(或分離 stdout 等),但我無法找到 Python 2.5/2.6 的任何解決方案.

Is there any way to write binary output to sys.stdout in Python 2.x? In Python 3.x, you can just use sys.stdout.buffer (or detach stdout, etc...), but I haven't been able to find any solutions for Python 2.5/2.6.

編輯,解決方案:來自 ChristopheD 的鏈接,如下:

EDIT, Solution: From ChristopheD's link, below:

import sys

if sys.platform == "win32":
    import os, msvcrt
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)

我正在嘗試將 PDF 文件(二進制形式)推送到標準輸出,以便在 Web 服務器上提供服務.當我嘗試使用 sys.stdout.write 寫入文件時,它會將各種回車添加到導致 PDF 呈現損壞的二進制流中.

I'm trying to push a PDF file (in binary form) to stdout for serving up on a web server. When I try to write the file using sys.stdout.write, it adds all sorts of carriage returns to the binary stream that causes the PDF to render corrupt.

編輯 2:對于這個項目,很遺憾,我需要在 Windows Server 上運行,所以 Linux 解決方案已經過時了.

EDIT 2: For this project, I need to run on a Windows Server, unfortunately, so Linux solutions are out.

簡單的虛擬示例(從磁盤上的文件讀取,而不是動態生成,只是為了讓我們知道生成代碼不是問題):

Simply Dummy Example (reading from a file on disk, instead of generating on the fly, just so we know that the generation code isn't the issue):

file = open('C:\test.pdf','rb') 
pdfFile = file.read() 
sys.stdout.write(pdfFile)

推薦答案

你在哪個平臺上?

你可以試試這個食譜 如果您使用的是 Windows(鏈接表明它是 Windows 特定的).

You could try this recipe if you're on Windows (the link suggests it's Windows specific anyway).

if sys.platform == "win32":
    import os, msvcrt
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)

網絡上有一些參考資料表明 Python 3.1 中會有/應該有一個函數以二進制模式重新打開 sys.stdout 但我真的不知道是否有比以上適用于 Python 2.x.

There are some references on the web that there would/should be a function in Python 3.1 to reopen sys.stdout in binary mode but I don't really know if there's a better alternative then the above for Python 2.x.

這篇關于Python 2.x - 將二進制輸出寫入標準輸出?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 91激情电影| 日韩超碰在线 | 四虎成人免费视频 | 欧美性猛交一区二区三区精品 | 欧美日韩精品一区二区三区蜜桃 | 99免费在线视频 | 黄色小视频入口 | 99久久精品一区二区成人 | 欧美精品一区二区三区蜜桃视频 | 中文字幕在线国产 | 天天拍天天操 | 日韩亚洲一区二区 | 国产成人午夜电影网 | 日韩中文字幕 | 夜夜摸夜夜操 | 日韩看片| 亚洲一区中文 | 欧美精品一区二区三区蜜桃视频 | 中国一级特黄真人毛片 | 日韩成年人视频在线 | 国产综合久久久久久鬼色 | 国产日韩一区二区三区 | 免费观看成人鲁鲁鲁鲁鲁视频 | 一级亚洲| 91精品国产综合久久久动漫日韩 | 国产成人免费观看 | 欧美一卡二卡在线 | 午夜欧美一区二区三区在线播放 | 91日b| 国产一极毛片 | 一区二区成人 | 特黄特黄a级毛片免费专区 av网站免费在线观看 | 成人在线视频观看 | 欧美一级α片 | 91免费视频观看 | 国产精品免费一区二区三区四区 | 亚洲伊人a| 久久久视频在线 | 波多野结衣在线观看一区二区三区 | 91av免费版| 天天操夜夜看 |