Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40287
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'classes,': 0.05; 'error:': 0.05; 'method.': 0.05; 'arguments': 0.07; 'constructor': 0.07; 'deprecated': 0.07; 'formatting': 0.07; 'msg': 0.07; 'subject:help': 0.07; 'python': 0.09; '__init__': 0.09; 'methods,': 0.09; 'typed': 0.09; 'typeerror:': 0.09; 'def': 0.10; '2.7': 0.13; 'size,': 0.13; 'file,': 0.15; 'end).': 0.16; 'lot!': 0.16; 'new-style': 0.16; 'syntaxerror:': 0.16; 'underscores': 0.16; 'underscores,': 0.16; 'variable.': 0.16; 'later': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'subject:need': 0.17; 'skip:" 30': 0.20; 'do.': 0.21; 'assuming': 0.22; 'back.': 0.22; 'color,': 0.22; 'fixing': 0.22; '(you': 0.23; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; 'forgot': 0.27; 'object,': 0.27; "doesn't": 0.28; 'run': 0.28; 'ball': 0.29; 'omitted': 0.29; 'definition': 0.29; 'class': 0.29; "i'm": 0.29; 'error': 0.30; 'file': 0.32; 'print': 0.32; 'message.': 0.33; '11,': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'front': 0.33; 'guys': 0.33; 'hi,': 0.33; 'skip:d 20': 0.34; 'that,': 0.34; 'version': 0.34; 'program,': 0.34; 'text': 0.34; 'thanks': 0.34; 'direction': 0.35; 'pm,': 0.35; 'posting': 0.35; 'sometimes': 0.35; 'something': 0.35; 'but': 0.36; 'useful': 0.36; 'should': 0.36; 'thank': 0.36; 'one,': 0.37; 'subject:: ': 0.38; 'supports': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'received:192': 0.39; 'space': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'your': 0.60; 'matter': 0.61; 'subject': 0.66; 'middle': 0.66; 'kindly': 0.67; 'color': 0.69; 'received:74.208': 0.71; 'special': 0.73; 'yours': 0.88 |
| Date | Fri, 01 Mar 2013 14:58:06 -0500 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: need for help |
| References | <8B3DE2FF-3A5A-4666-8FF6-70B15AAF5987@icloud.com> |
| In-Reply-To | <8B3DE2FF-3A5A-4666-8FF6-70B15AAF5987@icloud.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:0YZSFKMjR/ZN48WMM3ZbIiBmqsd0it3iRifofp2mFaF ikro2yu+OXSYIrA0EC+9v6jahNdu9O9bzBbkmnRrCsS27fwXG5 Af894221+9jKDt54hzUO8b9hbO3mnOXHWYFef5Zrq4c8v+L3VW KGbMRmp1NoKjS6T3AJbSAfZnORk6c8xxG+sl1ghFe47jDSKLgv dV22hU2NBnnsuMcCbnYhQoN8Zfobfe+GVyjgjjUf12DFTEF7bx w8fpsMIzYz8m4pgMQx6ZUhMbfMf8nLIuFVU0kRGiaW/CwcxckM kgSZ7p8HW5rm6J/X54JuDNpnc88xNcT6w52Akk4HfGnj/EIaQ= = |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2752.1362167902.2939.python-list@python.org> (permalink) |
| Lines | 79 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1362167902 news.xs4all.nl 6910 [2001:888:2000:d::a6]:53639 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:40287 |
Show key headers only | View raw
On 03/01/2013 01:35 PM, 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!
>
1) please pick a useful subject line. Every message "needs help". But
yours might be something like "constructor takes no arguments"
2) please tell us Python version you're targeting. I'm assuming 2.7
3) Thank you for giving a full traceback error message. Much better
than an image file, or just paraphrasing, as many do. And thanks for
posting as a text message, so your formatting doesn't get trashed.
When I run the program, I get:
davea@think2:~/temppython$ python leonardo.py
File "leonardo.py", line 13
print my ball
^
SyntaxError: invalid syntax
davea@think2:~/temppython$
Which is caused by having a space in the middle of the myball variable.
After fixing that, I get your error, which is triggered by misspelling
__init__ (you omitted one of the underscores at each end).
After fixing that, I get
davea@think2:~/temppython$ python leonardo.py
<__main__.ball instance at 0x7f330da5bbd8>
davea@think2:~/temppython$
which is triggered by the same error in the __str__ method. These
special methods are sometimes called dunder methods, because they all
need double underscores, at both front and back.
davea@think2:~/temppython$ python leonardo.py
hi, i am a small redball!
davea@think2:~/temppython$
The other thing you should fix is the class definition line. You forgot
to derive your class from object, which makes your class an old style
one, deprecated for many many years. Doesn't matter here, but sooner or
later it will. And Python 3 supports only new-style classes, so you
might as well be using them.
class ball(object): #new style class
--
DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: need for help Dave Angel <davea@davea.name> - 2013-03-01 14:58 -0500
csiph-web