How to open a pdf file in binary format - django

I want to read the metadata of pdf files so i am using pyPdf package but for some files i am facing error (i.e;PdfFileReader stream/file object is not in binary mode,it may not be read correctly)

You need to read the file in binary mode:
from pyPdf import PdfFileReader
with open('document.pdf', 'rb') as f:
pdf = PdfFileReader(f)

Related

C++ How to open .docx files in MFC

How can I open .docx files in MFC?
Because when I open a .docx file it puts "PK" to the editor. (This is at every .docx file I have opened)
.docx files are .zip files with a different extension. The content of the zip is essentially a directory structure containing various XML files.
To open a .docx in a text editor would basically require unzipping the file to a directory then opening each XML file in your editor.
The actual format of .docx files can be found online.

Reading raster directory with GDAL

Is it possible to read an entire directory of Geo - Tiff files "automatically" with GDAL C++ API or do I have to iterate manually on each file and open it with GDALOpen()?
You need to iterate and open each file.

How to download text file from url and save it in django project directory

I use django 1.11 and python 3.6
I have several text file links
Example:
http://mylinks/telechargement.php?file=file1.txt
http://mylinks/telechargement.php?file=file2.txt
Now It's possible to download it with python code ?
How can I download each of these files via the link and save it to a specific directory with python code without modifyin its structure ?
Thank for advance.
If you make use of the popular requests library, here's a simplistic solution for downloading a TXT file to a specific path:
import requests
example_txt = 'http://www.textfiles.com/100/914bbs.txt'
r = requests.get(example_txt)
with open('/path/to/file.txt', 'wb') as f:
f.write(r.content)

Create Lambda function using Python API (Boto3) by using zip file

I have a zip file ready for the lambda function, but in the doc, the zip file is required to be read as binary (so it seems). I can open the zip file and read the files inside as binary, but how do I read the zip file as a binary?
The doc: https://boto3.readthedocs.io/en/latest/reference/services/lambda.html#Lambda.Client.create_function
nevermind, a simple open(file_name, 'rb').read() does it for me. Forgot the 'b'.....

WEKA: Converting csv file to arff file

I am trying to convert csv file to arff file using ArffViewer (Tools -> ArffViewer -> File -> Save as...) With this the arff file is created but without any contents (empty file). My question is:
Why is it creating an empty file and how to fix it.
sample of csv file:
(All attribute types are nominal)