stringio

    3熱度

    3回答

    我使用Python 3.5和燒瓶0.10.1並喜歡它,但與send_file有點麻煩。我最終想要處理一個熊貓數據框(來自表單數據,在此示例中未使用,但將來必要時),並將其作爲csv(無臨時文件)下載。達到這個目標的最好方法就是給我們StringIO。 這裏是我嘗試使用代碼: @app.route('/test_download', methods = ['POST']) def test_dow

    -1熱度

    1回答

    StringIO的寫回磁盤我創建使用StringIO和zipfile在內存中的zip文件: inMemoryZip = StringIO() outfile = zipfile.ZipFile(inMemoryZip, 'w', compression=zipfile.ZIP_DEFLATED) //outfile.write(stuff) inMemoryZip.seek(0) retu

    1熱度

    2回答

    我遇到了此過程問題:我想使用requests下載圖像,然後使用PIL對其進行裁切,然後將其保存到型號ImageField。 這是我現在有: from django.core.files.base import ContentFile import requests from StringIO import StringIO from PIL import Image def get_i

    0熱度

    1回答

    我想嘗試閱讀簡單的圖像沒有這樣的文件或目錄,但我都有以下錯誤: import requests import pytesseract from PIL import Image from StringIO import StringIO from lxml import html session=requests.Session() cont=session.get('http://T

    0熱度

    1回答

    我意識到,當我使用pd.read_csv和StringIO創建數據框時將映射列存在問題,將文本字符串轉換爲數據框,然後使用字典映射特定列,因爲列會給我所有的映射的NaN值。這是爲什麼? 相比之下,如果列直接來自我直接創建的熊貓數據框,那麼當我直接使用字典映射列時,我沒有遇到錯誤。 這裏是代碼,其中的誤差來自於: import pandas as pd from io import StringI

    2熱度

    3回答

    喂予從2. 試圖端口小片段到Python 3的Python 2: def _download_database(self, url): try: with closing(urllib.urlopen(url)) as u: return StringIO(u.read()) except IOError: self.__show_excepti

    1熱度

    1回答

    StringIO在其代碼如下注意事項: Notes: - Using a real file is often faster (but less convenient). - There's also a much faster implementation in C, called cStringIO, but it's not subclassable. 「真正的文件往往是快

    3熱度

    1回答

    我寫了一個基準,我比較了不同字符串連接方法ZOCache。 因此,它看起來像這裏是tempfile.TemporaryFile比什麼都更快: $ python src/ZOCache/tmp_benchmark.py 3.00407409668e-05 TemporaryFile 0.385630846024 SpooledTemporaryFile 0.299962997437 Buffe

    -1熱度

    1回答

    我需要使字符串被bibtexparser的parsing_read讀取。據我瞭解,模塊,它只讀取文件,而不是流,所以我做了: text = "Some text" with open("/tmp/bibtmp.bib", "w") as bibfile: bibfile.write(text) self.parsing.parsing_read("/tmp/bibtmp.bib")

    0熱度

    1回答

    Ruby on Rails中的StringIO是什麼? 我想了解另一個SO回答引用StringIO,但它在我的頭上。 我會建議使用StringIO爲此,並確保您的SUT 接受流寫入而不是文件名。 testIO = StringIO.new sutObject.writeStuffTo testIO testIO.string.should == "Hello, world!" 來源:Rsp