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….)
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
.
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….)
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
.