Search code examples
pythonarrayspython-3.7

I am getting an error - (array() takes 0 positional arguments but 2 were given) while creating an array in python 3.7


"""
Array Operations
"""


def array():
    import array as arr
    my_array = arr.array('i', [1, 2, 3, 4])
    print(str(my_array))


array()

I am not sure what is wrong with the code as it works inside another class function.


Solution

  • Because you have a file called array.py, when you write

    import array
    

    you're actually importing your file array.py instead of the standard module array. If you rename your array.py file something else, you'll avoid this problem.