Append error when running visual studio code

Hi,

I am having an error on the append function as you can see below
Error:
4.5.3
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Traceback (most recent call last):
File “c:/Python/TEST.py”, line 46, in
DATA.append=((Landmark.x))
AttributeError: ‘list’ object attribute ‘append’ is read-only

I am running this in a for loop:
Data=
Data.append=((Landmark.x))
print(Data)

Thanks!

Please use three backquotes before and after your code so we can see the indentation.

append is a list method. To call a method you use parentheses, not an equals sign. So I think you intend:

Data = []
Data.append(Landmark.x)
print(Data)

Thank you.
Indeed that is the code I used.
But I still have the same error message:

AttributeError: ‘list’ object attribute ‘append’ is read-only

Please show your actual code. This is not the code that you pasted in your first message.

In terminal I get this error message:

Error:
4.5.3
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Traceback (most recent call last):
File “c:/Python/TEST.py”, line 33, in
Data.append=((Landmark.x))
AttributeError: ‘list’ object attribute ‘append’ is read-only

This is the code in visual studio code:

import cv2
print(cv2.__version__)
import mediapipe as mp
width=1280
height=720
cam=cv2.VideoCapture(0,cv2.CAP_DSHOW)
cam.set(cv2.CAP_PROP_FRAME_WIDTH,width)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT,height)
cam.set(cv2.CAP_PROP_FPS, 30)
cam.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc(*'MJPG'))

Handen=mp.solutions.hands.Hands(False,2,.5,.5,)

mpDraw=mp.solutions.drawing_utils

while True:
    ignore, frame=cam.read()    
    frameRGB=cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)    
    results=Handen.process(frameRGB)    
    if results.multi_hand_landmarks != None:
        for handLandmarks in results.multi_hand_landmarks:            
            mpDraw.draw_landmarks(frame,handLandmarks,mp.solutions.hands.HAND_CONNECTIONS)         
                       
            for Landmark in handLandmarks.landmark:              
                Data=[]
                Data.append=((Landmark.x))
                print(Data)               
                print('')                          
            
    cv2.imshow('my WEBcam',frame)
    cv2.moveWindow('my WEBcam',0,0)      
    if cv2.waitKey(1) & 0xff==ord('q'):
        break
cam.release()

No, it’s not. Your code is (incorrectly) using an equals sign. You are trying to assign to the append method.

Data.append=((Landmark.x))  # Can't assign to a method

The code I posted earlier has no equals sign, so it is not the same code.

Data = []
Data.append(Landmark.x)  # parenthesis call the method, not assign to it
print(Data)

You are still trying to run this code:

Data.append=((Landmark.x))

That is wrong. Take out the equals sign:

Data.append=((Landmark.x))  # WRONG! BAD! DON'T DO THIS.

Data.append(Landmark.x)     # This is the way.

Thanks a lot guys!
Did the adjustment and WORKS!
Have a nice day!!