Issue
At some point the tilde symbol ~ was no longer recognized as my home directory, only in Python. ~ still works with in terminal, so I'm not sure what happened but any insight on how to fix it you will save me some typing thanks!
On macOs Mojave
import os
tilde = '~'
print(os.path.exists(tilde))
os.system("if test -d ~; then echo 'exists'; fi")
OUTPUT:
False
exists
Solution
You have to use os.path.expanduser
on the path first. Try
print(os.path.exists(os.path.expanduser(tilde)))
instead.
Answered By - holdenweb
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.