Having trouble using os.path.isfile() method in Python

Python docs: os.path.isfile()

I’m trying to check if 'home/dominic/websites/beautifulsoup\\ docs/index.html' is a file but isfile returns False

I copied the path straight from the target file. Don’t know why its not working. Need help.

I usually use something like os.path.abspath() to make sure that the path is in the correct format.

yet works. i just didnt have to correct format. i removed the \ from the string

FWIW, different environments can have different file path conventions, so it’s generally not recommended to hard code in the path as a string.

yeh i was just using it for testing. there are a lot of useful modules in the standard lib to handle paths

Fair. I just thought I would mention it because I have fought that fight before.

1 Like