-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
432908a
commit f74657e
Showing
4 changed files
with
95 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import os | ||
|
||
|
||
def canonical(path): | ||
fs = [os.path.expandvars, os.path.expanduser, os.path.normcase] | ||
fs = [ | ||
os.path.expandvars, # expands variables like %name% or $NAME, perhaps rare on PATH | ||
os.path.expanduser, # expands ~, shell-dependent | ||
os.path.normcase, # to lowercase, to make prettier | ||
] | ||
for f in fs: | ||
path = f(path) | ||
return path | ||
return path | ||
|
||
|
||
print(os.path.exists("~")) # False | ||
print(os.path.exists(os.path.abspath("~"))) # False | ||
print(os.path.exists(canonical("~"))) # True | ||
print(os.path.exists("~")) # False | ||
print(os.path.exists(os.path.abspath("~"))) # False | ||
print(os.path.exists(canonical("~"))) # True | ||
print(os.path.isdir("~")) # False | ||
print(os.path.isdir(canonical("~"))) # True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters