Mercurial > hg > config
comparison python/_path.py @ 694:ebca6d85213a
File "/usr/lib/python3/dist-packages/IPython/config/__init__.py", line 16, in <module>
from .application import *
File "/usr/lib/python3/dist-packages/IPython/config/application.py", line 31, in <module>
from IPython.config.configurable import SingletonConfigurable
File "/usr/lib/python3/dist-packages/IPython/config/configurable.py", line 33, in <module>
from IPython.utils.text import indent, wrap_paragraphs
File "/usr/lib/python3/dist-packages/IPython/utils/text.py", line 28, in <module>
from IPython.external.path import path
File "/usr/lib/python3/dist-packages/IPython/external/path/__init__.py", line 2, in <module>
from path import *
File "/home/jhammel/python/path.py", line 25
print root(path)
^
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 09 Jul 2014 16:26:49 -0700 |
parents | python/path.py@c461ffb7af8c |
children |
comparison
equal
deleted
inserted
replaced
693:c7309e7625ba | 694:ebca6d85213a |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 """ | |
4 (filesystem) path utilities | |
5 | |
6 from http://stackoverflow.com/questions/12041525/a-system-independent-way-using-python-to-get-the-root-directory-drive-on-which-p | |
7 """ | |
8 | |
9 import os | |
10 | |
11 def is_root(path): | |
12 """is `path` the filesystem root""" | |
13 return not os.path.split(path)[1] | |
14 | |
15 def root(path): | |
16 """return filesystem root of path""" | |
17 path = os.path.abspath(path) | |
18 while not is_root(path): | |
19 path, tail = os.path.split(path) | |
20 return path | |
21 | |
22 if __name__ == '__main__': | |
23 import sys | |
24 for path in sys.argv[1:]: | |
25 print root(path) |