Total Pageviews

Popular posts


 os.path.abspath(os.path.join(PATH_TO_GET_THE_PARENT, os.pardir))

 If the given path exists

to check if the given path exists

path = '/home/john/temp' os.path.exists(path) #this returns false if path doesn't exist or if the path is a broken symbolic link

 check if the given path is a directory, file, symbolic link, mount point etc

to check if the given path is a directory

dirname = '/home/john/python' os.path.isdir(dirname)

to check if the given path is a file

filename = dirname + 'main.py' os.path.isfile(filename)

to check if the given path is symbolic link

symlink = dirname + 'some_sym_link' os.path.islink(symlink)

to check if the given path is a mount point

mount_path = '/home' os.path.ismount(mount_path) 

 Absolute Path from Relative Path

Use os.path.abspath:

>>> os.getcwd() '/Users/csaftoiu/tmp'

 >>> os.path.abspath('foo') '/Users/csaftoiu/tmp/foo'

 >>> os.path.abspath('../foo') '/Users/csaftoiu/foo' 

>>> os.path.abspath('/foo') '/foo'

No comments

ict note in A/L

3/Technology ict note in A/L/post-list