0

I saw a lot of questions about the same error, but I didn't find anyone that seems to be about the same thing.

A part (that seems relevant to me) of my code is:

falta = [0]
x = 0
o = 0
aux = a
while a in range(aux, len(repetido)):
    print("a %s" %a)
    x = 0
    while int(repetido[a].academia) != int(vetor[x].academia):
        print("repetido %s" % repetido[a].academia)
        print("vetor %s" %vetor[x].academia)
        x = x + 1
        if a == aux:
            falta[0] = int(vetor[x].inscricao)
            print("este eh o primeiro falta: %s" %falta[0])
        else:
            falta.append(int(vetor[x].inscricao))
        falta = random.shuffle(falta)
        a = a + 1

I get this error message:

File "C:/Users/vivia/PycharmProjects/karate/Teste posicoes repetidas.py", line 60, in posicionaAcademiaIgual

falta.append(int(vetor[x].inscricao))

AttributeError: 'NoneType' object has no attribute 'append'

I don't use this falta list on any other place in the program. Sorry about my poor English.

1
  • 1
    random.shuffle is a procedure in python parlance; it operates on the argument list in place and returns None. This is opposed to a function, which performs computations around its arguments, often without mutating them, and returns the result of the computation. See this Commented Oct 10, 2017 at 3:07

2 Answers 2

2

Just making my comment an official answer.

When you perform the assignment falta = random.shuffle(falta), falta becomes None, since random.shuffle operates in place and returns None. When you come around on your next iteration, falta has become none, and the AttributeError is thrown when you call falta.append.

Instead of

falta = random.shuffle(falta)

try

random.shuffle(falta)

And read this.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you sooo much, that's exatly it! Problem solved!
-1

I guess you are using random from numpy. the ranom.shuffle will return None, it shuffle the list in place. so change

falta = random.shuffle(falta)

to

andom.shuffle(falta)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.