Problem in 'array'

Write a Python program to get the current memory address and the length in elements of the buffer

used to hold an array’s contents and also find the size of the memory buffer in bytes.

array_num =  array('i',[1,2,5,3,8,7,9,11,45,])

print('Current memory address :',str(array_num.buffer_info()))
print('Length in elements of the buffer :', str(array_num.buffer_info()[1]))
print('Size of the memory buffer in bytes :',str(array_num.itemsize))

Error Message “Name error:name ‘array’ is not defined”

What is wrong with this code

array is a Python Standard Library module, as such it needs to be imported first.

You need to import array module. Just add the next line to your code:

from array import array

array_num =  array('i',[1,2,5,3,8,7,9,11,45,])
print('Current memory address :',str(array_num.buffer_info()))
print('Length in elements of the buffer :', str(array_num.buffer_info()[1]))
print('Size of the memory buffer in bytes :',str(array_num.itemsize))

The output is:

Current memory address : (1613985309152, 9)
Length in elements of the buffer : 9
Size of the memory buffer in bytes : 4

I got it . Tried. It works very well. Thank you.
The memory address shows as 40654192, 9. All other things are O.K.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.