Python Pathlib path object not converting to string [duplicate]
The problem is here: str = str(pdf.stem) You’re overwriting the value str, so starting from the 2nd iteration of your loop, str no longer refers to the built-in str function. Choose a different name for this variable.