Problems while applying a function to each element's content of a directory in python?
<p>I am trying to obtain the content of several .pdf files from a directory in order to transform them to text with tika library, however I believe that I am not reading the .pdf file objects correctly. This is what I tried so far:</p>

<p>Input:</p>

<pre><code>for filename in sorted(glob.glob(os.path.join(input_directory, '*.pdf'))):
    with open(filename,"rb") as f:
        print(f)
        text = parser.from_file(f)
</code></pre>

<p>Output: </p>

<pre><code>&lt;_io.BufferedReader name='/Users/user/Downloads/pdf-files/a_pdf_file.pdf'&gt;
AttributeError: '_io.BufferedReader' object has no attribute 'decode'
</code></pre>

<p>Which is the most efficient way of walking through the content of the files in python?.</p>

<p>The tika parser receives a path and opens the file itself:</p>

<pre><code>for filename in sorted(glob.glob(os.path.join(input_directory, '*.pdf'))):
    parsed = parser.from_file(filename)
    text = parsed['content']
</code></pre>

python python-3.x pdf io ipython-parallel