Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40285 > unrolled thread
| Started by | leonardo selmi <l.selmi@icloud.com> |
|---|---|
| First post | 2013-03-01 19:35 +0100 |
| Last post | 2013-03-01 14:59 -0800 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
need for help leonardo selmi <l.selmi@icloud.com> - 2013-03-01 19:35 +0100
Re: need for help Alister <alister.ware@ntlworld.com> - 2013-03-01 22:01 +0000
Re: need for help Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-01 14:59 -0800
| From | leonardo selmi <l.selmi@icloud.com> |
|---|---|
| Date | 2013-03-01 19:35 +0100 |
| Subject | need for help |
| Message-ID | <mailman.2750.1362166527.2939.python-list@python.org> |
hi guys
i typed the following program:
class ball:
def _init_(self, color, size, direction):
self.color = color
self.size = size
self.direction = direction
def _str_(self):
msg = 'hi, i am a ' + self.size + ' ' + self.color + 'ball!'
return msg
myball = ball('red', 'small', 'down')
print my ball
BUT I GOT THIS ERROR:
Traceback (most recent call last):
File "/Users/leonardo/Documents/ball2.py", line 11, in <module>
myball = ball('red', 'small', 'down')
TypeError: this constructor takes no arguments
can you kindly tell me what is wrong?
thanks a lot!
[toc] | [next] | [standalone]
| From | Alister <alister.ware@ntlworld.com> |
|---|---|
| Date | 2013-03-01 22:01 +0000 |
| Message-ID | <oz9Ys.269338$Cm3.268822@fx23.fr7> |
| In reply to | #40285 |
On Fri, 01 Mar 2013 19:35:14 +0100, leonardo selmi wrote:
> hi guys
>
> i typed the following program:
>
> class ball:
> def _init_(self, color, size, direction):
> self.color = color self.size = size self.direction = direction
>
> def _str_(self):
> msg = 'hi, i am a ' + self.size + ' ' + self.color + 'ball!'
> return msg
>
> myball = ball('red', 'small', 'down')
> print my ball
>
> BUT I GOT THIS ERROR:
>
> Traceback (most recent call last):
> File "/Users/leonardo/Documents/ball2.py", line 11, in <module>
> myball = ball('red', 'small', 'down')
> TypeError: this constructor takes no arguments
>
> can you kindly tell me what is wrong?
> thanks a lot!
as far as I can see is_init_ should be __init__ (double underscore)
--
The autodecrement is not magical.
-- Larry Wall in the perl man page
[toc] | [prev] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2013-03-01 14:59 -0800 |
| Message-ID | <5f6f9e76-d44c-463e-af3e-88ac7adddc35@googlegroups.com> |
| In reply to | #40285 |
On Friday, March 1, 2013 12:35:14 PM UTC-6, leonardo selmi wrote: > class ball: > > [...] > Now that you've gotten the exceptions sorted, it may be time to join the *other* 99% of programmers by editing that class identifier. All class symbols should start with (at minimum) a capitol letter. After you do that, you should start reading and adapting as much of the Python style guide you can handle. http://www.python.org/dev/peps/pep-0008/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web