Re: Which part of the loop is it going through in this class frame?

2018-03-09 Thread Cameron Simpson
On 08Mar2018 20:25, C W wrote: Thank you guys, lots of great answers, very helpful. I got it! A follow-up question: How did the value of "object" get passed to "time"? Obviously, they have different names. How did Python make that connection? Code is below for convenience. class Clock(object

Re: Which part of the loop is it going through in this class frame?

2018-03-08 Thread Steven D'Aprano
On Thu, 08 Mar 2018 20:25:42 -0500, C W wrote: > Thank you guys, lots of great answers, very helpful. I got it! > > A follow-up question: > > How did the value of "object" get passed to "time"? Obviously, they have > different names. How did Python make that connection? It didn't. You have misu

Re: Which part of the loop is it going through in this class frame?

2018-03-08 Thread C W
Thank you guys, lots of great answers, very helpful. I got it! A follow-up question: How did the value of "object" get passed to "time"? Obviously, they have different names. How did Python make that connection? Code is below for convenience. class Clock(object): def __init__(self, time):

Re: Which part of the loop is it going through in this class frame?

2018-03-08 Thread Steven D'Aprano
On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote: > Hello, > > I am new to OOP. I'm a bit confused about the following code. > > class Clock(object): > def __init__(self, time): > self.time = time Here you set the instance attribute "self.time". > def print_time(self): > t

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread dieter
C W writes: > I am new to OOP. I'm a bit confused about the following code. > > class Clock(object): > def __init__(self, time): > self.time = time > def print_time(self): > time = '6:30' > print(self.time) > > clock = Clock('5:30') > clock.print_time() > 5:30 > > I

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Frank Millman
"C W" wrote in message news:cae2fw2nudjcmvukavzh01trkqeentkdxdpbawcphhsgx8jv...@mail.gmail.com... Hello, I am new to OOP. I'm a bit confused about the following code. class Clock(object): def __init__(self, time): self.time = time def print_time(self): time = '6:30'

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Dan Sommers
On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote: > class Clock(object): > def __init__(self, time): > self.time = time > def print_time(self): > time = '6:30' > print(self.time) > > clock = Clock('5:30') > clock.print_time() > 5:30 > > I set time to 6:30, but it's c

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Dan Sommers
On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote: > Hello, > > I am new to OOP. I'm a bit confused about the following code. > > class Clock(object): > def __init__(self, time): > self.time = time > def print_time(self): > time = '6:30' > print(self.time) > > clock

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Dan Stromberg
On Wed, Mar 7, 2018 at 1:57 PM, C W wrote: > I set time to 6:30, but it's coming out to 5:30. I guess it's because I > passed in 5:30, so, it's replaced? time and self.time are 2 different things. > How does line-by-line execution run inside a frame To quickly come to grips with execution order

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Cameron Simpson
On 07Mar2018 16:57, C W wrote: I am new to OOP. I'm a bit confused about the following code. class Clock(object): def __init__(self, time): self.time = time def print_time(self): time = '6:30' print(self.time) clock = Clock('5:30') clock.print_time() 5:30 I set time

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Terry Reedy
On 3/7/2018 4:57 PM, C W wrote: Hello, I am new to OOP. I'm a bit confused about the following code. class Clock(object): def __init__(self, time): self.time = time def print_time(self): time = '6:30' print(self.time) Local name 'time' is bound to '6:30'.

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Ben Finney
C W writes: > I am new to OOP. Welcome, and congratulations on learning Python. > I'm a bit confused about the following code. > > def print_time(self): Begins a function definition. The function will receive one argument (the class instance), and bind the name ‘self’ to that. >

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread jladasky
On Wednesday, March 7, 2018 at 1:58:33 PM UTC-8, C W wrote: > Hello, > > I am new to OOP. There are (at least) two purposes for classes: 1) To group together data and functions in a meaningful way. Functions which are defined inside a class are called methods. 2) To allow the preservation of