[Tutor] The meaning of self

Glenn Lester glester at avant.ca
Wed Oct 23 18:01:24 CEST 2013


I have come across the term "self" in a number of Python scripts and as a
beginner to the language I am wondering if it has any specific meaning. It
is usually used in the same manner as in this example by Steven D'Aprano.


class DefaultModelCar:
    model = "Unknown"

    BRAKE_COMMAND = "B"
    FORWARD_COMMAND = "F"
    REVERSE_COMMAND = "R"
    ACCELERATE_COMMAND = "A"
    TURN_LEFT_COMMAND = "TL"
    TURN_RIGHT_COMMAND = "TR"

    def send_command(self, command):
        # Send a command to the model car.
        # Put the code here to actually communicate with the car.
        ...

    def forward(self):
        # Drive forward.
        if self.direction == "Reverse":
            # Brake first, then move forward.
            self.stop()
        self.send_command(self.
FORWARD_COMMAND)
        self.send_command(self.ACCELERATE_COMMAND)
        self.direction = "Forward"

    def reverse(self):
        if self.direction == "Forward":
            self.stop()
        self.send_command(self.REVERSE_COMMAND)
        self.send_command(self.ACCELERATE_COMMAND)
        self.direction = "Reverse"

    def stop(self):
        self.send_command(self.BRAKE_COMMAND)
        self.direction = "Stopped"


-- 

*Glenn Lester*

Software Tester

*Avant Systems Group***

*voice: *204.789.9596 x19* **|** fax: *204.789.9598* **|** email: *
glester at avant.ca*|** web: *www.avant.ca**



*Quality People Delivering Quality Solutions*

CONFIDENTIALITY NOTICE: This correspondence and any attachment(s) may
contain confidential information that is legally privileged. If you are not
the intended recipient, or the person responsible for delivering it, you
are hereby notified that any disclosure, copying, distribution or use of
any of the aforementioned information is STRICTLY PROHIBITED. If you have
received this transmission in error, please permanently delete the original
transmission and its attachments without reading or saving in any manner.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131023/2f0d9ace/attachment.html>


More information about the Tutor mailing list