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

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -