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