在Python中「向上」查找文件的最佳方式是什麼? (理想情況下,它也可以在Windows上運行)。例如,如何在Python中向上查找文件?
>>> os.makedirs('/tmp/foo/bar/baz/qux')
>>> open('/tmp/foo/findme.txt', 'w').close()
>>> os.chdir('/tmp/foo/bar/baz/qux')
>>> findup('findme.txt')
'/tmp/foo/findme.txt'
據我所知,在Python標準庫中沒有任何東西(雖然我很想被證明是錯誤的)。另外,使用谷歌搜索並沒有太多的確定性;我想知道是否有「大家」使用的東西。
os.isfile()不是一個函數。試試os.path.isfile()。 – nosklo 2009-05-22 20:21:23