Getting 'TypeError: 'list' object is not callable' error

Omar Shehab

In the following custom function:

def get_a_random_memory(length, lower_sum_range, upper_sum_range):

    memory = list()


    for i in range(0, length):
        memory.append((2 * random.randint(0, 1) - 1))


    sum = 0
    for i in range(0, length):
        if len(memory) == 0:
            sum = memory[i]
        else:
            sum = sum + memory[i]

I am getting the following error.

>>> print memories.get_a_random_memory(10, 1, 10)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\omarshehab\PycharmProjects\practice\memories.py", line 28, in get_a_random_memory
    if len(memory) == 0:
TypeError: 'list' object is not callable

I assume I am accessing the list variable memory correctly.

Any help please?

Martin Evans

You could consider doing it as follows:

def get_a_random_memory(length, lower_sum_range, upper_sum_range):
    memory = [(2 * random.randint(0, 1) - 1) for i in xrange(length)]
    total = sum(memory)

    print memory
    print total

get_a_random_memory(10, 0, 0)

You should avoid using sum as a variable as there is already a Python function with that name that performs the calculation automatically on a list.

This script would for example display:

[1, -1, -1, -1, -1, 1, 1, 1, -1, -1]
-2

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python Error: TypeError: 'list' object is not callable

From Dev

Python Convert set to list, keep getting TypeError: 'list' object is not callable

From Dev

Getting error list is not callable

From Dev

Getting error in Python 3.x : TypeError: 'int' object is not callable

From Dev

TypeError: 'list' object is not callable: why?

From Dev

"TypeError": 'list' object is not callable flask

From Dev

TypeError: 'list' object is not callable in python

From Dev

Python - TypeError: 'list' object is not callable

From Dev

Getting an error ; 'int' object not callable

From Dev

I keep getting a TypeError: 'str' object is not callable

From Dev

Why am I getting TypeError 'list' object is not callable when using map function?

From Dev

Getting a: "TypeError: 'numpy.float64' object is not callable" error in program related to Bessel functions

From Dev

TypeError: 'list' object is not callable, error calling extend from inherited list class

From Dev

Python Error: TypeError: 'NoneType' object is not callable

From Dev

Error in Calculator: TypeError: 'float' object is not callable

From Dev

Stepping into RFE and getting 'DataFrame object is not callable" error

From Dev

Map to List error: Series object not callable

From Dev

list() but 'str' object is not callable error in python

From Dev

Python program error 'list' object is not callable

From Dev

List Object Not Callable, Can't Find Error

From Dev

TypeError: 'bytes' object is not callable

From Dev

TypeError: 'Weather' object is not callable

From Dev

TypeError: 'Logger' object is not callable

From Dev

TypeError: 'class' object is not callable

From Dev

TypeError: 'unicode' object is not callable

From Dev

typeerror 'bytes' object is not callable

From Dev

TypeError: NoneType object is not callable

From Dev

"TypeError: 'set' object is not callable"

From Dev

TypeError: at / 'module' object is not callable

Related Related

  1. 1

    Python Error: TypeError: 'list' object is not callable

  2. 2

    Python Convert set to list, keep getting TypeError: 'list' object is not callable

  3. 3

    Getting error list is not callable

  4. 4

    Getting error in Python 3.x : TypeError: 'int' object is not callable

  5. 5

    TypeError: 'list' object is not callable: why?

  6. 6

    "TypeError": 'list' object is not callable flask

  7. 7

    TypeError: 'list' object is not callable in python

  8. 8

    Python - TypeError: 'list' object is not callable

  9. 9

    Getting an error ; 'int' object not callable

  10. 10

    I keep getting a TypeError: 'str' object is not callable

  11. 11

    Why am I getting TypeError 'list' object is not callable when using map function?

  12. 12

    Getting a: "TypeError: 'numpy.float64' object is not callable" error in program related to Bessel functions

  13. 13

    TypeError: 'list' object is not callable, error calling extend from inherited list class

  14. 14

    Python Error: TypeError: 'NoneType' object is not callable

  15. 15

    Error in Calculator: TypeError: 'float' object is not callable

  16. 16

    Stepping into RFE and getting 'DataFrame object is not callable" error

  17. 17

    Map to List error: Series object not callable

  18. 18

    list() but 'str' object is not callable error in python

  19. 19

    Python program error 'list' object is not callable

  20. 20

    List Object Not Callable, Can't Find Error

  21. 21

    TypeError: 'bytes' object is not callable

  22. 22

    TypeError: 'Weather' object is not callable

  23. 23

    TypeError: 'Logger' object is not callable

  24. 24

    TypeError: 'class' object is not callable

  25. 25

    TypeError: 'unicode' object is not callable

  26. 26

    typeerror 'bytes' object is not callable

  27. 27

    TypeError: NoneType object is not callable

  28. 28

    "TypeError: 'set' object is not callable"

  29. 29

    TypeError: at / 'module' object is not callable

HotTag

Archive