Solution for scandir iterator not behaving according to documentation (Win10, py 3.9.6)
is Given Below:
EDIT: Colons are if statements are really kind of important, aren’t they?
I’m having terrible difficulty getting a list of files in my working data directory. Have tried listdir and scandir to same result, a Syntax Error raise at runtime start, before it even transitions over to the IDLE window.
import os import numpy import pandas as pd i = 0 for f in os.scandir(r'C:\Users\scott.d.lee\Desktop\datafiles'): i = i + 1 print("processing file #",i,"[",f,"] ...") this_df = pd.read_csv(f, skipinitialspace=True, header=0, index_col="sid", on_bad_lines="warn", names=cols) print(this_df.columns)
And it’s blowing up on the for-loop line, believing there’s a syntax error at the end of that line.
Any ideas, o friendly spirits of the internet?