Home > Net >  Create PDFs inside a one specific folder
Create PDFs inside a one specific folder

Time:07-14

In my code I first create a folder:

if not os.path.exists("my_folder"):
  os.mkdir("my_folder")

After my script makes multiple pdf`s. However, I would like the pdfs to all to end up inside that specific folder. I have tried:

pdf=PDF()
with open(os.path.join("my_folder", pdf), 'w') as pdf:
   pdf.add_page()

But, I get this Error TypeError: expected str, bytes or os.PathLike object, not NoneType. Can someone help me?

CodePudding user response:

First of all - you are re-assigning pdf variable. First you initialise it here:

pdf=PDF()

then here:

with open(os.path.join("my_folder", pdf), 'w') as pdf:

another thing - in os.path.join("my_folder", pdf) you are trying to join string with pdf instance. What does PDF() return? A string?

Overall code should look something like this:

pdf=PDF()
pdf.add_page()
with open(os.path.join('my_folder', 'pdf_file.pdf'), 'w') as fp:
    fp.write(pdf)
   
  • Related