Skip to content
Advertisement

Trying to use os.path.exists via variables but getting an error

I have a file called serial.dll. The content of this file is another file’s name:

JavaScript

I also have 1 file called a-2ED1-7156.dll in the same directory.

When I try to check if the file exists by reading its name from serial.dll:

JavaScript

Always results “no”.

but:

JavaScript

Always gives the correct result.

How can I check if the file a-2ED1-7156.dll exists by reading it from the serial.dll file?

JavaScript

Advertisement

Answer

Your problem is that lines in a file might end with the new-line character. File names usually don’t have that character… For example, right now you’re checking if the file a-2ED1-7156.dlln exists – which is not. You simply need to strip() the lines before checking them as files:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement