Вопрос

ipdb> os.listdir(SPREADSHEETS_DIR)
['Report Mar.xlsx']
ipdb> fff = os.listdir(SPREADSHEETS_DIR)[0]
ipdb> fff
'Report Mar.xlsx'
ipdb> os.path.isfile(fff)
False

Why is that? I know I could check the extension, but isn't os.path.isfile supposed to work with such files?

Это было полезно?

Решение

If you do os.listdir(SPREADSHEETS_DIR), you get the contents of that directory directly. But these have to be interpreted relative to this path.

Try

ffg = os.path.join(SPREADSHEETS_DIR, fff)
ffg # to look at
os.path.isfile(ffg)

and you'll find out that it works.

(Note that I follow you in the process of using very bad variable names...)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top