[파이썬] os 파일인지 확인: `os.path.isfile()`

Here’s an example of how you can use os.path.isfile() to check if a path is a file:

import os

path = 'path/to/file.txt'

if os.path.isfile(path):
    print(f"{path} is a file.")
else:
    print(f"{path} is not a file.")

In the above code, we first import the os module. Then, we declare a variable path which stores the path to the file we want to check.

Next, we use the os.path.isfile() function to check if the path variable points to a file. If it does, we print a message saying that the path is a file. Otherwise, we print a message saying that it is not a file.

Remember to replace 'path/to/file.txt' with the actual path you want to check. You can also use variables or ask for user input to get the path dynamically.