I am trying to list all the TIFF files in a folder using python. I found an answer to this SO question, and adapted its code as follows:
import os
import glob
from itertools import chain
def list_tifs_rec(path):
return (chain.from_iterable(glob(os.path.join(x[0], '*.tif')) for x in os.walk(path)))
def concatStr(xs):
return ','.join(str(x) for x in xs)
But I got a runtime error about 'module' object is not callable
, when I tried to execute it as follows:
>>> l = list_tifs_rec("d:/temp/")
>>> concatStr(l)
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 9, in concatStr
File "<string>", line 9, in <genexpr>
File "<string>", line 6, in <genexpr>
TypeError: 'module' object is not callable
I come from a C++ background and don't know Python generators very well. I googled around and didn't find close examples of this error, probably because of its generality.
Can anyone please explain the error and how to fix it?
Thanks.
You need to call
glob.iglob
(the method), not justglob
(the module), like so: