Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LED control menu
#12
Self is created when the instance of a class is created. So, there is no self outside the __init__ method. You can remove self. part or do it like this. Try it. I am not really sure of what I am talking about. This is how I understand all that classy classiness Smile

    def __init__(self):
        self.selected_option = 0
        self.options = [
        'On',
        'Off',
        ]
        self.actions = [
            self.handle_On,
            self.handle_Off,
            ]
__init__ method is executed when an instance of a class is created. Self is a reference to that instance. self.object is called instance object and defining one outside of the __init__ method obviously is causing this error.

In the other side are the class objects. You just define them as regular objects inside the class definition

class Foo:
    def __init__(self, obj_1, obj_2, obj_3):
        self.one = obj_1 # instance attribute
        self.two = obj_2 # instance attribute

    three = obj_3 # class attribute
Because class objects are owned by the class they are shared between all instances of that class. While the instance objects are different for every instance of that class.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
LED control menu - by trippyt - May-31-2018, 06:43 AM
RE: LED control menu - by wavic - May-31-2018, 06:59 AM
RE: LED control menu - by trippyt - May-31-2018, 01:55 PM
RE: LED control menu - by trippyt - May-31-2018, 07:22 AM
RE: LED control menu - by wavic - May-31-2018, 09:27 AM
RE: LED control menu - by trippyt - May-31-2018, 11:58 AM
RE: LED control menu - by wavic - May-31-2018, 12:02 PM
RE: LED control menu - by trippyt - May-31-2018, 12:10 PM
RE: LED control menu - by wavic - May-31-2018, 12:49 PM
RE: LED control menu - by wavic - May-31-2018, 02:30 PM
RE: LED control menu - by trippyt - May-31-2018, 02:40 PM
RE: LED control menu - by wavic - May-31-2018, 03:19 PM
RE: LED control menu - by trippyt - May-31-2018, 03:35 PM
RE: LED control menu - by wavic - May-31-2018, 03:42 PM
RE: LED control menu - by trippyt - May-31-2018, 03:51 PM
RE: LED control menu - by wavic - May-31-2018, 04:02 PM
RE: LED control menu - by trippyt - May-31-2018, 04:13 PM
RE: LED control menu - by wavic - May-31-2018, 04:47 PM
RE: LED control menu - by trippyt - May-31-2018, 04:53 PM
RE: LED control menu - by wavic - May-31-2018, 05:18 PM
RE: LED control menu - by trippyt - May-31-2018, 05:45 PM
RE: LED control menu - by trippyt - May-31-2018, 06:58 PM
RE: LED control menu - by wavic - May-31-2018, 07:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Remote control of the Visual Studio 2013 debug menu using Python MariusTo 0 2,511 Jan-17-2018, 04:58 PM
Last Post: MariusTo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020