Issue
im trying to pass the address of an array reg_value[2]
to a function in python
import array
reg_value = array.array('I',[0]*100)
def postdata(data):
for i in range(2):
print(data[i])
reg_value[0]=1
reg_value[1]=2
reg_value[2]=3
reg_value[3]=4
postdata(reg_value)
the above code prints the value 1 2
but i need to pass the address of reg_value[2]
to print the value 3 4
i can achieve this in C programming like passing the address as ®_value[2]
how to replicate the same in python?
Solution
You can't pass the address of anything in Python, but you can pass a slice which contains a subsequence.
postdata(reg_value[2:])
This does create a copy of the items from the sequence. Probably a better design is to allow the caller to specify a base index.
def postdata(items, offset=0):
for i in range(2):
print(items[offset+i])
Answered By - tripleee Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.