#π valid file path
23 messages Β· Page 1 of 1 (latest)
@warm trail
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
not if it exists\
os.path.isfile works
but I want to see if the dir is valid I think?
import os
if os.path.exists(r"c:\Users\x.txt"):
print(True)
else:
print(False)
returns False
use exists, yes.
then call it on the parent
in os.path that's done via something like dirname
can you give me an example pls ?
in pathlib it'd be
p = Path(r"c:\Users\x.txt")
assert p.parent.exists(), p
so it checks if c:\Users exists?
alr !
what does it do tho
like how do I get a True or False
Path.exists(*, follow_symlinks=True)```
Return `True` if the path points to an existing file or directory.
This method normally follows symlinks; to check if a symlink exists, add the argument `follow_symlinks=False`...
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.