Why
re.search("\.docx", os.listdir(os.getcwd()))
print the following error?
TypeError: expected string or buffer
Because it os.listdirreturns list, but re.searchwants a string.
os.listdir
list
re.search
The easiest way to do what you do:
[f for f in os.listdir(os.getcwd()) if f.endswith('.docx')]
Or even:
import glob glob.glob('*.docx')
re.search()expects stras the second argument. Contact docs to find out more.
re.search()
str
import re, os a = re.search("\.docx", str(os.listdir(os.getcwd()))) if a: print(True) else: print(False)
Source: https://habr.com/ru/post/1535260/More articles:Google PHP API API: Insufficient Resolution - phpWhy can't BCrypt authenticate in this context? - sinatraHow to align text like a trapezoid? - javascriptCSS помещает объект html в качестве содержимого - htmlSilex, Symfony2 FormServiceProvider - SLOW - performanceApache access log for the most common bash script IP address - linuxAngularDart Element onResize event not associated with a window - dartКак scrollTop div, чей контент управляется AngularDart? - dartDART - resizing a div element - dartCabal says it can't find the module - haskellAll Articles