본문 바로가기

typeerror6

Python TypeError: Unicode-objects must be encoded before hashing를 어떻게 수정할 수 있나요?, How to correct TypeError: Unicode-objects must be encoded before hashing? 질문 나는 이 오류를 가지고 있습니다: Traceback (most recent call last): File "python_md5_cracker.py", line 27, in m.update(line) TypeError: Unicode-objects must be encoded before hashing 나는 Python 3.2.2에서 이 코드를 실행하려고 할 때: import hashlib, sys m = hashlib.md5() hash = "" hash_file = input("해시가 있는 파일 이름은 무엇입니까? ") wordlist = input("워드리스트는 무엇입니까? (파일 이름을 입력하세요) ") try: hashdocument = open(hash_file, "r") except IO.. 2023. 11. 16.
Python 파이썬에서 "finally" 절이 왜 필요한가요?, Why do we need the "finally" clause in Python? 질문 나는 왜 우리가 try...except...finally 문에서 finally가 필요한지 잘 모르겠다. 내 의견으로는, 이 코드 블록 try: run_code1() except TypeError: run_code2() other_code() 는 finally를 사용한 이 코드와 똑같다: try: run_code1() except TypeError: run_code2() finally: other_code() 뭔가 빠진 것인가? 답변 이렇게 반환하는 경우 차이가 있습니다: try: run_code1() except TypeError: run_code2() return None # 메서드가 반환되기 전에 finally 블록이 실행됩니다. finally: other_code() 이와 비교: try: ru.. 2023. 10. 11.
Python3에서 StringIO를 사용하는 방법은 무엇인가요?, How to use StringIO in Python3? 질문 나는 Python 3.2.1을 사용하고 StringIO 모듈을 가져올 수 없습니다. io.StringIO를 사용하고 작동하지만 numpy의 genfromtxt와 함께 사용할 수 없습니다: x="1 3\n 4.5 8" numpy.genfromtxt(io.StringIO(x)) 다음 오류가 발생합니다: TypeError: Can't convert 'bytes' object to str implicitly import StringIO를 작성하면 다음과 같이 나타납니다: ImportError: No module named 'StringIO' 답변 제가 import StringIO를 작성하면 해당 모듈이 없다고 나옵니다. 파이썬 3.0에서 새로운 내용에 따르면: StringIO와 cStringIO 모듈은 사.. 2023. 9. 8.
Python 파이썬 3에서 파일 내용을 처리할 때 'str'이 아닌 바이트 유사 객체가 필요합니다(TypeError: a bytes-like object is required, not 'str')., "TypeError: a bytes-like object is required, not 'str'" when handling file conten.. 질문 나는 매우 최근에 Python 3.5로 이전했다. 이 코드는 Python 2.7에서 제대로 작동했다: with open(fname, 'rb') as f: lines = [x.strip() for x in f.readlines()] for line in lines: tmp = line.strip().lower() if 'some-pattern' in tmp: continue # ... code 하지만 3.5에서 if 'some-pattern' in tmp: continue 라인에서 오류가 발생하여 다음과 같이 말합니다: TypeError: a bytes-like object is required, not 'str' 나는 in의 양쪽에 .decode()를 사용하여 문제를 해결할 수 없었으며, if tm.. 2023. 6. 27.