Why exactly is os.stat(pathname) failing here for you and what does catching the exception save us from?