python newbie needs help

This is the place for queries that don't fit in any of the other categories.

python newbie needs help

Postby vredes » Fri May 03, 2013 3:34 pm

hi,
i ran across these codes in a book i read:

>>> class Giraffes:
def __init__(self, spots):
self.giraffe_spots = spots

when I assign an object, let's say:
harold=Giraffe(100)
the error message quickly pops up. The funny thing is when I copy the codes for the class above directly from the ebook, I could assign the object, but when I typed it myself the codes just don't run. What I understand from the error message is that the object doesn't need parameter. Please help me.
Thank you.
vredes
 
Posts: 3
Joined: Fri May 03, 2013 3:21 pm

Re: python newbie needs help

Postby Yoriz » Fri May 03, 2013 6:53 pm

Hi your class is named Giraffes with an s and then when you are creating an instance of it you have used Giraffe without the s.
When you post code could you please use code tags to preserve code indentation and also paste the traceback error that you get from your code.
The following link tells you about how to post, please have a read :D thanks.
http://www.python-forum.org/viewtopic.php?f=6&t=145
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1007
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: python newbie needs help

Postby vredes » Mon May 06, 2013 10:41 am

I'm sorry. but here's how I wrote it. please find the error:
Code: Select all
>>> class Giraffes:
   def _init_(self, spots):
      self.giraffe_spots=spots

      
>>> ozwald= Giraffes(100)
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    ozwald= Giraffes(100)
TypeError: object() takes no parameters


thank you
vredes
 
Posts: 3
Joined: Fri May 03, 2013 3:21 pm

Re: python newbie needs help

Postby metulburr » Mon May 06, 2013 10:56 am

you have _init_ instead of __init__
note the 2 double underscores
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1490
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: python newbie needs help

Postby vredes » Mon May 06, 2013 11:29 am

Thank you. I must have missed the explanation
vredes
 
Posts: 3
Joined: Fri May 03, 2013 3:21 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests