expression - python re.search error TypeError: expected string or buffer -


why

re.search("\.docx", os.listdir(os.getcwd())) 

yield following error?

typeerror: expected string or buffer

because os.listdir returns list re.search wants string.

the easiest way doing is:

[f f in os.listdir(os.getcwd()) if f.endswith('.docx')] 

or even:

import glob glob.glob('*.docx') 

Comments

Popular posts from this blog

What can cause "Required Package 'IndyCore' not found" when compiling a Delphi 2010 project? -

Change the color of an oval at click in Java AWT -