python 오류 발생TypeError:'NoneType'object is not subscriptable 해결 방법
python을 쓸 때 이 오류가 발생했습니다. 그리고 인터넷의 튜토리얼의 해결 방안은 거의 모두 "이 변수를 다시 정의하십시오."라고 보았습니다.
나중에 내가 리턴 노네의 방법을 변수에 부여한 것을 발견하고 변수를 조작하여 직접 코드를 붙였다
for i in range(2000):
read_lines = random.shuffle(read_lines) #
print(read_lines)
어째서 보기에는 아무런 문제가 없지만, 운행하자마자 잘못을 보고한다
>>TypeError: 'NoneType' object is not subscriptable
나중에 원래random을 발견했어요.shuffle 이 함수는 return None이지만, 나는 그를read_lines, 다음 작업이 진행 중read_lines는 항상 이 오류입니다. 인쇄read_ 포함라인도 틀렸어요.이것은 랜덤 라이브러리에 있는 코드입니다.
def shuffle(self, x, random=None):
"""
Shuffle list x in place, and return None.
Optional argument random is a 0-argument function returning a
random float in [0.0, 1.0); if it is the default None, the
standard random.random will be used.
"""
if random is None:
randbelow = self._randbelow
for i in reversed(range(1, len(x))):
# pick an element in x[:i+1] with which to exchange x[i]
j = randbelow(i+1)
x[i], x[j] = x[j], x[i]
else:
_int = int
for i in reversed(range(1, len(x))):
# pick an element in x[:i+1] with which to exchange x[i]
j = _int(random() * (i+1))
x[i], x[j] = x[j], x[i]
솔루션위 줄의 값 부여 문장을 고치면 된다
for i in range(2000):
random.shuffle(read_lines)
print(read_lines)
content_list = []
총결산python 오류 발생 Type Error:'None Type'object is not subscriptable 해결 방법에 대한 이 글은 여기에 소개되었습니다. 더 많은 관련python 오류 발생 Type Error 해결 내용은 저희 이전의 글을 검색하거나 아래의 관련 글을 계속 훑어보십시오. 앞으로 많은 응원 부탁드립니다!