Re: [Tutor] Can this be done easly

2010-09-19 Thread Peter Otten
Roelof Wobben wrote:

>> Hint: why does this work:
>>
>>> def __init__(self, x=0, y=0):
>>
>> ...while this doesnt:
>>
>>> def _init_(self, base_point, width=0, length=0):
>>
>> Peter

> Maybe because base_point has no value ?

No. One __init__ has two underscores (correct) on each side, the other 
_init_ only one (wrong).

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can this be done easly

2010-09-19 Thread Alan Gauld


"Roelof Wobben"  wrote


When I change everything to this :

class Rectangle(object):
   def _init_(self, base_point, width=0, length=0):
   self.base_point = base_point
   self.width = width
   self.length = length

punt = Point(3,4)
rechthoek = Rectangle (punt,20,30)

I get this message :

Traceback (most recent call last):
 File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 13, 
in 

   rechthoek = Rectangle (punt,20,30)
TypeError: object.__new__() takes no parameters


Very odd, but are you using IDLE or a similar IDE?
Have you remembered to reload the module? Just a thought...

Alan G.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can this be done easly

2010-09-19 Thread Roelof Wobben




> To: tutor@python.org
> From: __pete...@web.de
> Date: Sun, 19 Sep 2010 18:04:25 +0200
> Subject: Re: [Tutor] Can this be done easly
>
> Roelof Wobben wrote:
>
>> When I change everything to this :
>
>> I get this message :
>>
>> Traceback (most recent call last):
>> File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 13, in
>> 
>> rechthoek = Rectangle (punt,20,30)
>> TypeError: object.__new__() takes no parameters
>
> Hint: why does this work:
>
>> def __init__(self, x=0, y=0):
>
> ...while this doesnt:
>
>> def _init_(self, base_point, width=0, length=0):
>
> Peter
>
> ___
> Tutor maillist - Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Hoi, 
 
Maybe because base_point has no value ?

Roelof
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can this be done easly

2010-09-19 Thread Peter Otten
Roelof Wobben wrote:

> When I change everything to this :

> I get this message :
>  
> Traceback (most recent call last):
>   File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 13, in
>   
> rechthoek = Rectangle (punt,20,30)
> TypeError: object.__new__() takes no parameters

Hint: why does this work:
  
>  def __init__(self, x=0, y=0):

...while this doesnt:

> def _init_(self, base_point, width=0, length=0):

Peter

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can this be done easly

2010-09-19 Thread Roelof Wobben




> Date: Sun, 19 Sep 2010 14:19:46 +0200
> From: knack...@googlemail.com
> To: tutor@python.org
> Subject: Re: [Tutor] Can this be done easly
>
> Am 19.09.2010 10:49, schrieb Roelof Wobben:
>>
>>
>> Hello,
>>
>> I have this programm :
>>
>> class Point:
>> def __init__(self, x=0, y=0):
>> self.x = x
>> self.y = y
>>
>> class Rectangle(Point):
>> def _init_(self, width=0, length=0):
>> self.width = width
>> self.length = length
> You're inheriting the Point Class, but you don't initialise it.
> For some detailled description of inheritance in Python I rather suggest
> to check out some tutorials instead of trying to explain it. Also,
> others on this list can do this probably better. Here's one reference:
> http://diveintopython.org/object_oriented_framework/index.html
>
> But now some remarks regarding your problem:
>
> First, I would not consider a Rectangle as a special Point. It's not a
> relation like a Sportscar is a Car (is-a-relationship). It's more a
> relation a Rectangle has 4 Points (has-a-relationship), or 1 Point and a
> width and length. So, it's probably better to express your Rectangle
> class like this:
>
> class Rectangle(object):
> def __init__(self, base_point, width=0, length=0):
> self.base_point = base_point
> self.width = width
> self.length = length
>
> then you go (with German names ;-)):
>
> punkt = Point(3,4)
> rechteck = Rectangle(punkt,20,30)
>
> In your Rectangle class, the __init__ method takes only two arguments
> (not counting the instance: self), but you're passing three arguments.
>
> At the beginning, the error messages are a bit confusing, because they
> count the instance as one of the arguments. So it tells you, that you
> have given 4 arguments, but you might wonder "Hey, I gave you 3".
>
> HTH,
>
> Jan
>
>>
>> punt = Point(3,4)
>> rechthoek = Rectangle (punt,20,30)
>>
>> Now I wonder how I can change this to rechthoek = rectangle (punt,20,20)
>> This one gives as error message :
>>
>> Traceback (most recent call last):
>> File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 12, in
>> rechthoek = Rectangle (punt,20,30)
>> TypeError: __init__() takes at most 3 arguments (4 given)
>>
>> Roelof
>>
>> ___
>> Tutor maillist - Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
> ___
> Tutor maillist - Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Hello, 
 
When I change everything to this :
 
class Point:
 def __init__(self, x=0, y=0): 
 self.x = x
 self.y = y
 
class Rectangle(object):
def _init_(self, base_point, width=0, length=0):
self.base_point = base_point
self.width = width
self.length = length

punt = Point(3,4)
rechthoek = Rectangle (punt,20,30)
 
I get this message :
 
Traceback (most recent call last):
  File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 13, in 
rechthoek = Rectangle (punt,20,30)
TypeError: object.__new__() takes no parameters
 
Roelof
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can this be done easly

2010-09-19 Thread Knacktus

Am 19.09.2010 10:49, schrieb Roelof Wobben:



Hello,

I have this programm :

class Point:
  def __init__(self, x=0, y=0):
  self.x = x
  self.y = y

class Rectangle(Point):
 def _init_(self, width=0, length=0):
 self.width = width
 self.length = length

You're inheriting the Point Class, but you don't initialise it.
For some detailled description of inheritance in Python I rather suggest 
to check out some tutorials instead of trying to explain it. Also, 
others on this list can do this probably better. Here's one reference:

http://diveintopython.org/object_oriented_framework/index.html

But now some remarks regarding your problem:

First, I would not consider a Rectangle as a special Point. It's not a 
relation like a Sportscar is a Car (is-a-relationship). It's more a 
relation a Rectangle has 4 Points (has-a-relationship), or 1 Point and a 
width and length. So, it's probably better to express your Rectangle 
class like this:


class Rectangle(object):
def __init__(self, base_point, width=0, length=0):
self.base_point = base_point
self.width = width
self.length = length

then you go (with German names ;-)):

punkt = Point(3,4)
rechteck = Rectangle(punkt,20,30)

In your Rectangle class, the __init__ method takes only two arguments 
(not counting the instance: self), but you're passing three arguments.


At the beginning, the error messages are a bit confusing, because they 
count the instance as one of the arguments. So it tells you, that you 
have given 4 arguments, but you might wonder "Hey, I gave you 3".


HTH,

Jan



punt = Point(3,4)
rechthoek = Rectangle (punt,20,30)

Now I wonder how I can change this to rechthoek = rectangle (punt,20,20)
This one gives as error message  :

Traceback (most recent call last):
   File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 12, in
 rechthoek = Rectangle (punt,20,30)
TypeError: __init__() takes at most 3 arguments (4 given)

Roelof

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor