0
나는이 다음 코드 :파이썬 - 형식 오류 : 예상 문자열이나 바이트와 같은 객체
import re
meshTerm = {}
meshNumber = {}
File = 'file.bin'
with open(File, mode='rb') as file:
readFile = file.read()
outputFile = open('output.txt', 'w')
for line in readFile:
term= re.search(r'MH = .+', line)
print(term)
내가 코드를 실행하면, 나는 다음과 같은 오류 얻을 : 왜 그
Traceback (most recent call last):
File "myFile.py", line 13, in <module>
term = re.search(r'MH = .+', line)
File "C:\Python35\lib\re.py", line 173, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or bytes-like object
입니다? 문제를 어떻게 해결할 수 있습니까?
감사합니다.
친절한 답변을 보내 주셔서 감사합니다. TypeError : 바이트 형 객체에 문자열 패턴을 사용할 수 없습니다. – Simplicity
위의 오류에 대한 대답입니다. 그것은 내가 문자열 패턴 대신 바이트 패턴을 사용해야합니다 : http://stackoverflow.com/questions/5184483/python-typeerror-on-regex – Simplicity
@ Simplicity 오 죄송합니다, 네가 할 수있는 또는 텍스트 파일에서 읽을 수 파일에 문자열이 있다면''rb''를''r''로 바꾸면됩니다. – umutto