Object modifying

i need help in a python program, i was creating a program in which there is a class and creating an object from it should become a list, i posted this question on another forum too tho i did not get lot of help. This is example code of what i want to achieve:

class Myclass(list):
     def __init__(self,val1,val2,val3):

this results an error when i create a variable using this class which i have no idea how to solve, and when i try to call the variable after encountering the error then the variable is not defined and i get NameError

so can anyone tell how to create list object from this class and then even edit it??

You can use Markdown formatting to write code. Wrap it in triple backticks like this; it’ll keep your formatting as well:

paste your code here
    indent is preserved

You can get Python syntax highlighting by appending python after the first backtick trio:

if ok:
    print("hello, world")  # comment

It will look like this:

if ok:
    print("hello, world")  # comment

Use the edit button to reformat your first post.

Regarding your code, you should use self.append iso. Myclass.append.

See NameError in the docs. You’ll get that error if you refer to a variable using the wrong name. For example using the wrong class name (c = MyClass(1, 2, 3)) will generate that error.

1 Like

thx for help, it worked

1 Like