def cd(path_to):  # pylint: disable=invalid-name
    """cd to the given path

    If the path is a file, then cd to its parent directory

    Remember current directory before the cd
        so that we can cd back there with cd('-')
    """
    if path_to == '-':
        if not cd.previous:
            raise PathError('No previous directory to return to')
        return cd(cd.previous)
    if not hasattr(path_to, 'cd'):
        path_to = makepath(path_to)
    try:
        previous = os.getcwd()
    except OSError as e:
        if 'No such file or directory' in str(e):
            return False
        raise
    if path_to.isdir():
        os.chdir(path_to)
    elif path_to.isfile():
        os.chdir(path_to.parent)
    elif not os.path.exists(path_to):
        return False
    else:
        raise PathError('Cannot cd to %s' % path_to)
    cd.previous = previous
    return True
def cd ( path_to ) : if path_to == '-' : if not cd . previous : raise PathError ( 'No previous directory to return to' ) return cd ( cd . previous ) if not hasattr ( path_to , 'cd' ) : path_to = makepath ( path_to ) try : previous = os . getcwd ( ) except OSError as e : if 'No such file or directory' in str ( e ) : return False raise if path_to . isdir ( ) : os . chdir ( path_to ) elif path_to . isfile ( ) : os . chdir ( path_to . parent ) elif not os . path . exists ( path_to ) : return False else : raise PathError ( 'Cannot cd to %s' % path_to ) cd . previous = previous return True
cd to the given path

    If the path is a file, then cd to its parent directory

    Remember current directory before the cd
        so that we can cd back there with cd('-')