Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98700
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | John Wong <gokoproject@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: What is wrong in this example code? |
| Date | Thu, 12 Nov 2015 10:10:06 -0500 |
| Lines | 84 |
| Message-ID | <mailman.273.1447341014.16136.python-list@python.org> (permalink) |
| References | <1b204966-46c6-4890-a5a5-8addd20343a1@googlegroups.com> <383401eb-f8be-4f7a-bd63-3520eedc069e@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de njB6jtD4yRvhieM2IKp4Hgi2lbHeFnX0XDiZI0ZSDb0Q== |
| Return-Path | <gokoproject@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; '"""': 0.05; 'modified': 0.05; 'subject:code': 0.07; 'cc:addr:python-list': 0.09; 'defined.': 0.09; 'snippet': 0.09; 'python': 0.10; 'syntax': 0.13; 'thursday,': 0.13; 'def': 0.13; 'thu,': 0.15; 'cc:name:python list': 0.16; 'range,': 0.16; 'rather,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'somehow.': 0.16; 'syntaxerror:': 0.16; 'xrange': 0.16; '\xc2\xa0if': 0.16; 'wrote:': 0.16; 'case.': 0.18; "shouldn't": 0.18; '>': 0.18; 'email addr:gmail.com>': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'this:': 0.23; 'thanks,': 0.24; 'second': 0.24; 'header:In-Reply-To:1': 0.24; 'skip:_ 20': 0.26; 'error': 0.27; 'message-id:@mail.gmail.com': 0.27; 'url:mailman': 0.30; 'code': 0.30; 'error.': 0.31; 'seconds': 0.31; 'fixed': 0.31; 'skip:_ 10': 0.32; 'run': 0.33; 'class': 0.33; 'url:python': 0.33; 'curious': 0.33; 'url:listinfo': 0.34; 'url:eu': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'could': 0.35; 'nov': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'skip:& 10': 0.37; '12,': 0.37; 'received:209': 0.38; 'hi,': 0.38; 'skip:x 10': 0.40; 'url:mail': 0.40; 'still': 0.40; 'space': 0.40; 'some': 0.40; 'advanced': 0.61; 'more': 0.63; 'different': 0.63; 'minutes': 0.64; 'hours': 0.65; 'skip:\xc2 10': 0.67; 'link:': 0.69; 'sounds': 0.76; 'subject:this': 0.85; 'url:php': 0.86; 'glad': 0.87 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=EqK2d7ce75f6F1vuEYUWNRUxCfaJMXALyNOBmnK7x5Q=; b=AHUFkmTRnEtm6DkCjXaSaIGJoRSksuj7gsJ72lzKo7BFS6DGHtuPDpPN3+PJok3hP4 HD/A0AA7NLhhjeBOf7YxPk+2qV0kxpLCQy4a8IOELwdi2vPC/h5eLoRker5D4ORylRbP V92apfg9Qvo8C47jcSb/88bCB9N10DzKRnHepQrcQVHbPtjYQ2hG1zWMCU4SZn0Rsk3/ wmLQHMTplIxWmIB3+eo/oOAxlmATYoAWnRG9+ysVArGbMCxMLEBEQoZsLOZX0M6UmV13 aiS8y6Y87+wOgdx0at3HILJ0BR72f4sI+TcOAsR3Bqw8sMXdY5oIEUHPuHgAcCfQLHrm kAkA== |
| X-Received | by 10.129.113.5 with SMTP id m5mr15001510ywc.128.1447341006084; Thu, 12 Nov 2015 07:10:06 -0800 (PST) |
| In-Reply-To | <383401eb-f8be-4f7a-bd63-3520eedc069e@googlegroups.com> |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.20+ |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:98700 |
Show key headers only | View raw
If you are using Python 3 you will need to change xrange to range, but the
error shouldn't be invalid syntax. I remember it should just name name not
found/not defined. So if you are not using Python 3, range and xrange do
still in Python 2 and they have different use case.
So i am really curious how you fixed it. It sounds more like some issue
with space rather, but still glad you solved it somehow.
On Thu, Nov 12, 2015 at 9:07 AM, fl <rxjwg98@gmail.com> wrote:
> On Thursday, November 12, 2015 at 8:58:33 AM UTC-5, fl wrote:
> > Hi,
> >
> > I run a code snippet from link:
> > http://www.python-course.eu/inheritance_example.php
> >
> > It is found that there is an error in this loop:
> >
> > for i in xrange(10000):
> > x.tick()
> > print(x)
> > SyntaxError: invalid syntax
> >
> >
> > I have modified it to:
> > for i in x range(10000):
> > x.tick()
> > print(x)
> > SyntaxError: invalid syntax
> >
> > it still has an error. What could be wrong?
> >
> > Thanks,
> >
> >
> > ....
> > class Clock(object):
> >
> > def __init__(self,hours=0, minutes=0, seconds=0):
> > self.__hours = hours
> > self.__minutes = minutes
> > self.__seconds = seconds
> >
> > def set(self,hours, minutes, seconds=0):
> > self.__hours = hours
> > self.__minutes = minutes
> > self.__seconds = seconds
> >
> > def tick(self):
> > """ Time will be advanced by one second """
> > if self.__seconds == 59:
> > self.__seconds = 0
> > if (self.__minutes == 59):
> > self.__minutes = 0
> > self.__hours = 0 if self.__hours==23 else self.__hours+1
> > else:
> > self.__minutes += 1;
> > else:
> > self.__seconds += 1;
> >
> > def display(self):
> > print("%d:%d:%d" % (self.__hours, self.__minutes,
> self.__seconds))
> >
> > def __str__(self):
> > return "%2d:%2d:%2d" % (self.__hours, self.__minutes,
> self.__seconds)
> >
> > x = Clock()
> > print(x)
> > for i in xrange(10000):
> > x.tick()
> > print(x)
>
> Solved it by this:
> print(x)
> for i in range(1, 10000):
> x.tick()
> print(x)
>
> Thanks,
> --
> https://mail.python.org/mailman/listinfo/python-list
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What is wrong in this example code? fl <rxjwg98@gmail.com> - 2015-11-12 05:57 -0800
Re: What is wrong in this example code? fl <rxjwg98@gmail.com> - 2015-11-12 06:07 -0800
Re: What is wrong in this example code? John Wong <gokoproject@gmail.com> - 2015-11-12 10:10 -0500
Re: What is wrong in this example code? Larry Hudson <orgnut@yahoo.com> - 2015-11-12 15:59 -0800
Re: What is wrong in this example code? Nathan Hilterbrand <nhilterbrand@gmail.com> - 2015-11-12 19:24 -0500
csiph-web