문제

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