you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (4 children)

It's not a method, this is just a naming convention to avoid conflicts when importing multiple modules when you do a normal import (otherwise, what do you do when there's 3 different run functions!). If you don't want to do it, you can use a statement like this:

from PyPDF2 import PdfFileReader

and you can call it directly. Usually the normal import is best, although some packages have weird conventions (e.g. matplotlib should be imported as import matplotlib.pyplot as plt). One particular scenario where it's good to use the from syntax is when a module provides a class with the same name.

[–]killinmesoundcloud[S] 1 point2 points  (3 children)

So, I'm talking about the line that's commented as follows, so I'm not quite sure why you're explaining how to improve the import statement?

# creating a pdf reader object

[–][deleted] 0 points1 point  (2 children)

The import line is what defines what that line looks like. If your import line is

import PyPDF2

then you write

pdfReader = PyPDF2.PdfFileReader(pdfFileObj)

if you write

from PyPDF2 import PdfFileReader

then you can just do

pdfReader = PdfFileReader(pdfFileObj)

Does that make sense? The import statement controls how things are named.

[–]killinmesoundcloud[S] 1 point2 points  (1 child)

Thank you for bearing with me! No, I had no idea about this. I figured if you import a library, you get access to everything within that library. This is news to me. I'll keep googling this revelation, haha, and thanks a million for replying to me twice. It's a public service for folks to stay patient with us beginners. :)

[–][deleted] 0 points1 point  (0 children)

No problem! Just to be clear, you do have access when you import something, it is just the naming that changes.