• 51 Posts
  • 13 Comments
Joined 1 year ago
cake
Cake day: June 6th, 2023

help-circle
































  • Wilshire@beehaw.orgtoPython@lemmy.ml*Permanently Deleted*
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    If you’re reading the file path from standard input, you could try using the os.path.normpath() function from the os module to normalize the file path before passing it to the PdfReader function. This function converts a pathname to the normal form for the current operating system, which could help resolve any issues with the file path.

    Here’s an example of how you could use this function:

    import os
    from PyPDF2 import PdfReader
    
    def main():
        path = input('Whatever: ')
        normalized_path = os.path.normpath(path)
        reader = PdfReader(normalized_path)
    

    Give this a try and let me know if it helps!


  • Wilshire@beehaw.orgtoPython@lemmy.ml*Permanently Deleted*
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    1 year ago

    I hope this isn’t against the rules.

    ChatGPT4: It seems that the issue you’re facing is related to the way you’re passing the file path to the PdfReader function. One possible solution could be to use a raw string for the file path by adding an r before the opening quotation mark of the string. For example: path = r"C:\Users\example input.pdf".

    Another solution could be to use double backslashes \ instead of single backslashes \ in the file path. You could also try using forward slashes / instead of backslashes.

    Have you tried any of these solutions? Let me know if they work for you