Is there a particular reason why solution for Problem Set 6 has the following code in StandardRobot() and RandomWalkRobot() definitions def __init__(self, room, speed): Robot.__init__(self, room, speed) The rest of my code is very similar to solution. I don't however define inits in subclasses and the code works just fine.
Dear Sakh, __init__ is a special function which is used for initialization of variable.When ever you create a class,there is a initialization function which executes automatically and the task of the function is to create all the global variable required for the class(Not local function variables). We have the facility in python and in many more languages like C,to edit this automatically executable function and add extra line of print out to tell the user that the data is initializing.For example, >>>print 'Initialization is on' I haven't seen the problem set three but I can tell you from the two lines you have updated that it is a initialization function named which is written after the word def. The next line suggesting me that it is trying to provoke the Robot class's initialization function by writing Robot.__init__(self,room,speed). After writing the class name it is using the dot operator and then the function name which is (__init__) and after that giving the 'current' function's name(self),room and speed as a argument/parameter to the function. Remember that the underscores before and after the name is a syntax and can't be omitted. I hope it will help you out.Thank u
Are you just defining the room and speed all over again?
@shandelman I haven't seen the code yet,please attach the code for me and than it would be easier for me to explain the code. In above comment I have just described the use of the initialization named __init__,nothing about the code as I haven't seen it yet.
I think you mean sakh, not me.
@shandelman Nope, both are inherited and nothing changes. Speed is a constant and room is a whole separate class. I don't undrstand why this gets coded explicitly.
I would think that you wouldn't need to redefine __init__ unless you were planning on overriding parts of it.
Here is the course solution to make things easier: http://pastebin.com/ECG0ZyNk
" I don't however define inits in subclasses and the code works just fine. " ditto
Join our real-time social learning platform and learn together with your friends!