-3

Example:

f = open (path/pdf1.pdf)
f1 = open (path/pdf2.pdf)
f2 = open (path/pdf3.pdf)

Can the above be ran in a loop?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • glob library should come in handy if want to load all pdfs in path or using a prefix like following. ```from glob import glob;glob('pdf*.pdf')``` – Zeel B Patel Mar 14 '21 at 15:32
  • 1
    Does this answer your question? [Find all files in a directory with extension .txt in Python](https://stackoverflow.com/questions/3964681/find-all-files-in-a-directory-with-extension-txt-in-python) – Tomerikoo Mar 14 '21 at 16:00

1 Answers1

1

Yes, here is one implementation of a loop (f string needs python 3):


for x in range(1,4):
    f = open(path/ (f"pdf{x}.pdf"))

Note that this doesn't do anything with the file though. This also doesn't follow best file practices (really should use a context manager). Can't be more specific without know what you want to do with the file.

user1558604
  • 947
  • 6
  • 20