Welcome, guest | Sign In | My Account | Store | Cart
import os

# i am big on absolute paths, so i made it return an absolute path
# also that makes the results clearer.
def full_path(dir_):
    if dir_[0] == '~' and not os.path.exists(dir_):
        dir_ = os.path.expanduser(dir_)
    return os.path.abspath(dir_)

if __name__ == '__main__':
    print os.path.abspath(full_path('~/test')) # returns /home/rv/~/test if it exists or else it outputs /home/rv/test

Diff to Previous Revision

--- revision 1 2010-06-16 22:47:53
+++ revision 2 2010-06-16 23:17:20
@@ -8,4 +8,4 @@
     return os.path.abspath(dir_)
 
 if __name__ == '__main__':
-    print os.path.abspath('~/test') # returns /home/rv/~/test if it exists or else it outputs /home/rv/test
+    print os.path.abspath(full_path('~/test')) # returns /home/rv/~/test if it exists or else it outputs /home/rv/test

History