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

c# - Unity IoC Lifetime per HttpRequest for UserStore -

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

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -