using classes

Peter J. Holzer hjp-python at hjp.at
Fri Mar 13 06:12:15 EDT 2020


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 are calling it with

    self = (the newly created object)
    bez  = "Fiat Marea"
    ge   = 50
    ins  = 0

and an extra Parameter 1, Python doesn't know what to do with that
parameter, so it complains about it:

Traceback (most recent call last):
  File "joepareti54", line 19, in <module>
    fiat = PKW("Fiat Marea",50,0,1)
TypeError: __init__() takes 4 positional arguments but 5 were given

        hp

PS: Please add spaces after commas. «PKW("Fiat Marea", 50, 0, 1)» is
    much easier to read than «PKW("Fiat Marea",50,0,1)».

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20200313/51791ad1/attachment.sig>


More information about the Python-list mailing list