Error Collections
TypeError: expected string or bytes-like object
yunajoe
2022. 8. 20. 21:33
When to occur?!
- 주로 정규표현식을 사용할 때 나타나며, 전처리 대상물이 str이 아닐 때 나타난다.
x = [1, 'A', 2, 'B', 5, 'C', 'D', 'E']
x = re.sub("[^a-zA-Z]","",x)
cf. #re.sub("찾을패턴","찾을 패턴을 변경할 내용","원본")
How to Fix it?!
- 리스트 안에 elements들을 문자열로 바꿔주면 된다.
x = [1, 'A', 2, 'B', 5, 'C', 'D', 'E']
x = re.sub("[^a-zA-Z]", "", str(x) )