0

I'm quite the newbie regarding Python, and I got this code from someone else. Now I'm trying to figure out if these are good Python programming practices or just a redundant definition somehow.

I got this Controller class, which is related to some other classes, and, within the definitions I see that the Robot Class object is passed to a Data Class object, and it is directly assigned to a member of the Data Class object.

class RobotClass():
    def __init__(self):
        self.addresses   =   [0x03,
                              0x04,
...

class Data():
    def __init__(self, robot, ui):
        self.robot = robot

...
class Controller():
    def __init__(self):
        self.robot = RobotClass()
        self.ui = UI()
        self.data = Data(self.robot, self.ui)
...
controller = Controller()

My question is: are both variables (Robot Class object and Data Class member) the same? Will any change in the one reflect in the other? Or they are different from the instant of the assignment?

framosf
  • 1
  • 3
  • 2
    The Python docs carefully avoid the terms "pass by reference" and "pass by value" because the terms are used inconsistently across communities. Know this: 1. Python is call by assignment. The formal parameter names are assigned to the actual arguments after a call. 2. Assignment never copies data. – timgeb Jun 07 '17 at 13:03
  • 1
    From the duplicate: *Arguments are passed by assignment.*. You may want to read up on Python and names in this really excellent presentation: https://nedbatchelder.com/text/names.html – Martijn Pieters Jun 07 '17 at 13:06
  • And http://www.effbot.org/zone/call-by-object.htm which is *also* linked in the dupe. Python doesn't work quite like other languages, which is why some things are surprising at first when you come from languages that talk about references and values. – Wayne Werner Jun 07 '17 at 13:11
  • Yet another way of looking at it: *every* variable in Python as as its value a reference to an object, so from that standpoint it is call-by-value. – chepner Jun 07 '17 at 13:15
  • Thank you for your quick answers! @MartijnPieters: I had already seen that post, but I thought there might be some difference with the use of several classes and assignements. I will check on the presentation, and it will surely clear the clouds. Sorry for bothering. – framosf Jun 07 '17 at 16:16

0 Answers0