[转]正则匹配时对象必须为string or bytes-like object
逛segmentfault时碰到这个问题,发现早就在stackoverflow上被解决了。
报错:Expected string or bytes-like object
只需将传递的对象转成字符串就可以了。
As you stated in the comments, some of the values appeared to be floats, not strings.
You will need to change it to strings before passing it to re.sub.
The simplest way is to change location to str(location) when using re.sub.
It wouldn't hurt to do it anyways even if it's already a str.
letters_only = re.sub("[^a-zA-Z]", # Search for all non-letters
" ", # Replace all non-letters with spaces
str(location))
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步