How to use a variable instead of a constant in the following statement in python with PyPDF2

Question:

object = PyPDF2.PdfFileReader(r"C:PROYECTOSPruebasPDFArchivosPDF326581098.pdf")

changing the path for a variable, how would the sentence be

path = "C:PROYECTOSPruebasPDFArchivosPDF326581098.pdf"

object = PyPDF2.PdfFileReader(r….)

Asked By: Panyvino

||

Answers:

you should be able to use

path = r"C:PROYECTOSPruebasPDFArchivosPDF326581098.pdf"
object = PyPDF2.PdfFileReader(path)

The reason why the leading r is necessary are the symbols: In a normal string (without leading r) they are interpreted in a special way (for example "t" is a string with a single tabulator, while r"t" is a string with a and a t.

Answered By: Michael Kopp
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.