1

I am trying to get xml file of all my pdfs in the path, and for that I want to use pdfminer code from https://github.com/euske/pdfminer/blob/master/tools/pdf2txt.py on python 3. I installed pdfminer.six and all the related packages as well. However there is one problem with opening the files with file('', 'rb'), which should be replaced with open ('', 'rb'). But the output that I get from open () is not the same with file (), therefore the function written on github link is not running my pdf files.

For instance,

in python 2, the following code returns;

fp = file(filepath, 'rb') 

<open file '...\\lehsfil2.pdf', mode 'rb' at 0x04ADB180>

whereas the correspondence of file() function in python 3 returns;

fp = open(filepath, 'rb') 

<_io.BufferedReader name='...\\lehsfil2.pdf'>

Is there a direct correspondence of file() in python2, to python3, which returns the same object?

2
  • 1
    In python2 open is returning a file the same way as file (see stackoverflow.com/questions/32131230/python-file-function for details). In python3 file has been removed but open continue to work as in python2 with slightly the same API. What error do you have when you try to replace file by open in the code? I took a look at the library and all the use of the api should be present on both python2 and python3. Commented Aug 30, 2019 at 15:20
  • Please explain the specific error, preferably with a stacktrace if available. Commented Sep 24, 2019 at 22:13

1 Answer 1

1

The file() method was only available in Python 2.

The open() method returns a file type object in Python 2 and the same in Python 3. No major changes there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.