I’m looking to iterate a script over all files in the present working directory without iterating over scripts (so any extension .py). I was prevously using this
for fileName in os.listdir('.'):
if fileName != 'autocorrelation1.py':
with open(fileName, "r") as input:
REST OF SCRIPT HERE
Which worked when I only had the one script autocorrelation.py in the folder, but now I have a few python scripts I was wondering if there were a bash-style equivalent of * for example
for fileName in os.listdir('.'):
if fileName != *'.py':
with open(fileName, "r") as input:
REST OF SCRIPT HERE
I guess I am being lazy and could do it in another line of code but was just wondering if anyone knew a more fun way!
I recommend using the fnmatch module:
The glob module could help you find matching files, if that was what you wanted: