pop() for arrays

OpenMV related project discussion.
pielou10
Posts: 5
Joined: Tue Mar 26, 2019 12:03 pm

pop() for arrays

Postby pielou10 » Thu Mar 28, 2019 11:26 pm

Hey everyone,
Im trying to make a buffer with a fixed side, essentially I'm popping the first value, then appending the new value to the end of the array.
For some reason pop() doesn't seem to work and i'm wondering if this simply isnt in this version of Python? If so how would you recommend making this small buffer?

Thanks for your help!
Pierre Louet
User avatar
kwagyeman
Posts: 3044
Joined: Sun May 24, 2015 2:10 pm

Re: pop() for arrays

Postby kwagyeman » Fri Mar 29, 2019 1:49 am

What exactly doesn't work?

I've done this before:

Code: Select all

list = []
...
list.append(1234)
if len(list) > 4:
    list.remove(0)
This creates a 4 sample buffer.
Nyamekye,
pielou10
Posts: 5
Joined: Tue Mar 26, 2019 12:03 pm

Re: pop() for arrays

Postby pielou10 » Sun Mar 31, 2019 1:10 am

I have tried this also:
green_line_array.remove(0)
although it says "AttributeError: 'array' object has no attribute 'remove'" which is the same effect as writing pop, could this be a version issue?
User avatar
kwagyeman
Posts: 3044
Joined: Sun May 24, 2015 2:10 pm

Re: pop() for arrays

Postby kwagyeman » Sun Mar 31, 2019 11:41 am

Hi, what code are you executing? Did my above code work?
Nyamekye,
User avatar
iabdalkader
Posts: 834
Joined: Sun May 24, 2015 3:53 pm

Re: pop() for arrays

Postby iabdalkader » Mon Apr 01, 2019 2:42 pm

pop() without index removes the last item not the first, try

Code: Select all

l.pop(0)

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests