Path


Data structures Strings Public

Hard  

30min


Write a function that provides change directory (cd) function for an abstract file system.

Notes:

  • Root path is '/'.
  • Path separator is '/'.
  • Parent directory is addressable as '..'.
  • Directory names consist only of English alphabet letters (A-Z and a-z).

For example:

path = Path('/a/b/c/d')
print(path.cd('../x').current_path)

should display '/a/b/c/x'.

Note: Do not use built-in path-related functions.

Python 3.5.1
   

  •   Example case: AttributeError: 'NoneType' object has no attribute 'current_path':
  •   Two times down: AttributeError: 'NoneType' object has no attribute 'current_path':
  •   Two times up: AttributeError: 'NoneType' object has no attribute 'current_path':
  •   Complex paths: AttributeError: 'NoneType' object has no attribute 'current_path':