문제

I want to manipulate a downloaded PDF using PyPDF and for that, I need a file object.

I use GAE to host my Python app, so I cannot actually write the file to disk.

Is there any way to obtain the file object from URL or from a variable that contains the file contents?

TIA.

도움이 되었습니까?

해결책

Most tools (including urllib) already give you a file-like, but if you need true random access then you'll need to create a StringIO.StringIO and read the data into it.

다른 팁

In GAE you can use the blobstore to read, write file data and to upload and download files. And you can use the File API:

Example :

_file = files.blobstore.create(mime_type=mimetype, _blobinfo_uploaded_filename='test')
with files.open(_file, 'a') as f :                                                      
    f.write(somedata)                                                         
files.finalize(_file)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top