Python: TypeError: object of type 'NoneType' has no len()

前端 未结 4 1239
-上瘾入骨i
-上瘾入骨i 2021-02-14 15:56

I am getting an error from this Python code:

with open(\'names\') as f:
    names = f.read()
    names = names.split(\'\\n\')
    names.pop(len(names) - 1)
    n         


        
4条回答
  •  孤城傲影
    2021-02-14 16:53

    shuffle(names) is an in-place operation. Drop the assignment.

    This function returns None and that's why you have the error:

    TypeError: object of type 'NoneType' has no len()
    

提交回复
热议问题