Re: using classes

2020-03-13 Thread Pieter van Oostrum
joseph pareti wrote: > one more question. In the code below, there are 2 init() methods, one for > the class 'Fahrzeug' and > one for the class 'PKW'. > The program works when I instantiate the class as: > > fiat = PKW("Fiat Marea",50,0) > > but it fails if I say: > > fiat = PKW("Fia

Re: using classes

2020-03-13 Thread Peter J. Holzer
On 2020-03-13 09:46:29 +0100, joseph pareti wrote: > The program works when I instantiate the class as: > > fiat = PKW("Fiat Marea",50,0) > > but it fails if I say: > > *fiat = PKW("Fiat Marea",50,0,1)* The __init__ method of PKW has this signature: > def __init__(self, bez, ge, ins): You

Re: using classes

2020-03-13 Thread joseph pareti
one more question. In the code below, there are 2 init() methods, one for the class 'Fahrzeug' and one for the class 'PKW'. The program works when I instantiate the class as: fiat = PKW("Fiat Marea",50,0) but it fails if I say: *fiat = PKW("Fiat Marea",50,0,1)* *Traceback (most recent call l

Re: using classes

2020-03-12 Thread Pieter van Oostrum
joseph pareti writes: > thank you, that fixes it. I also noticed that both statements work: > > super(PKW, self).__init__(bez,ge) > > or > >super().__init__(bez,ge) The first is the required Python 2 calling (at least the first argument is required). The second way can be used

Re: using classes

2020-03-12 Thread Barry
> On 12 Mar 2020, at 14:28, joseph pareti wrote: > > thank you, that fixes it. I also noticed that both statements work: > > super(PKW, self).__init__(bez,ge) This form is for python 2 compatibility. > > or > > super().__init__(bez,ge) This is the python 3 way. If you do not

Re: using classes

2020-03-12 Thread joseph pareti
thank you, that fixes it. I also noticed that both statements work: super(PKW, self).__init__(bez,ge) or super().__init__(bez,ge) Am Do., 12. März 2020 um 12:58 Uhr schrieb MRAB : > On 2020-03-12 10:54, joseph pareti wrote: > > The following code that uses a class 'Fahrzeug' an

Re: using classes

2020-03-12 Thread MRAB
On 2020-03-12 10:54, joseph pareti wrote: The following code that uses a class 'Fahrzeug' and an inherited class 'PKW' runs correctly. However, if I use the 'super ' statement in in the PKW class, it ends with the following error message: *Traceback (most recent call last): File "erben_a.py",

Re: Using Classes

2010-06-26 Thread Mag Gam
Oh wow. You went beyond :-) Let me rewrite the example. I only want to calculate the wait time which is basically the depart time minus the arrival time for multiple days. This is all on 1 station. June 26, 2010: Trian A, Arrived at 6:00AM, Depart at 9:00AM Trian B, Arrived at 2:00AM, Depart at

Re: Using Classes

2010-06-25 Thread Mag Gam
Thanks everyone for your responses. They were very useful and I am glad I asked the question. I think having a concrete example would help me better, lets say I have this. Trian A, Arrived at 6:00AM Jun 25, Left at 8:00AM Jun 25 Trian B, Arrived at 2:00AM Jun 26, Left at 12:00AM Jun 26 Trian C,

Re: Using Classes

2010-06-25 Thread geremy condra
On Thu, Jun 24, 2010 at 9:04 AM, Alf P. Steinbach /Usenet wrote: > * Mag Gam, on 24.06.2010 13:58: >> >> I have been using python for about 1 year now and I really like the >> language. Obviously there was a learning curve but I have a programing >> background which made it an easy transition. I p

Re: Using Classes

2010-06-24 Thread Nathan Rice
As others have mentioned when you would like to encapsulate data and functions together, they're useful. Also, if you find yourself passing lists/tuples/dictionaries around frequently, you might benefit from converting them into classes. This tends to make the code clearer and more readable, you

Re: Using Classes

2010-06-24 Thread Alf P. Steinbach /Usenet
* Mag Gam, on 24.06.2010 13:58: I have been using python for about 1 year now and I really like the language. Obviously there was a learning curve but I have a programing background which made it an easy transition. I picked up some good habits such as automatic code indenting :-), and making my

Re: Using Classes

2010-06-24 Thread Neil Cerutti
On 2010-06-24, Bruno Desthuilliers wrote: > Not going into OO when you don't need it IS actually the > "Python way" !-) My most satisfying classes are the ones that gradually coalesce from a functional program. They take actual shape during refactoring. I find classes to be the most successful w

Re: Using Classes

2010-06-24 Thread Bruno Desthuilliers
Mag Gam a écrit : I have been using python for about 1 year now and I really like the language. Obviously there was a learning curve but I have a programing background which made it an easy transition. I picked up some good habits such as automatic code indenting :-), and making my programs more

Re: Using classes in python

2006-10-27 Thread Colin J. Williams
trevor lock wrote: > Hello, > > I've just started using python and have observed the following : > > class foo: > a=[] > def __init__(self, val): > self.a.append ( val ) > def getA(self): > print self.a > return self.a > > z = foo(5) > y = foo(4) >

Re: Using classes in python

2006-10-25 Thread Gabriel Genellina
At Wednesday 25/10/2006 16:19, trevor lock wrote: I've just started using python and have observed the following : class foo: a=[] def __init__(self, val): self.a.append ( val ) It's a common pitfall. As seen just a few days ago: http://groups.google.com/group/comp.lang.py

Re: Using classes in python

2006-10-25 Thread Éric Daigneault
trevor lock wrote: > Hello, > > I've just started using python and have observed the following : > > class foo: > a=[] > def __init__(self, val): > self.a.append ( val ) > def getA(self): > print self.a > return self.a > > z = foo(5) > y = foo(4) > z.