Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19173

Re: Weird Loop Behaviour

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <arnodel@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.028
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'received:209.85.214.174': 0.13; 'cc:addr:python-list': 0.15; '0))': 0.16; '255': 0.16; '3),': 0.16; 'seconds,': 0.16; '\xc2\xa0if': 0.16; 'wrote:': 0.16; 'trying': 0.20; 'cc:no real name:2**0': 0.21; 'header:In-Reply- To:1': 0.22; 'figure': 0.23; 'thus': 0.23; 'cc:2**0': 0.25; 'code': 0.25; 'seconds': 0.25; 'code,': 0.27; 'message- id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'skip:\xc2 20': 0.30; 'received:209.85.214': 0.32; 'instead': 0.33; 'hi,': 0.34; 'routine': 0.34; 'something': 0.35; 'run': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'screen': 0.38; 'should': 0.38; "couldn't": 0.39; 'received:209': 0.39; 'expected': 0.39; 'subject:: ': 0.39; '8bit%:8': 0.40; 'skip:\xc2 10': 0.74; 'respectively': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=m7pnrEXF6h+SrhjDiNnW84f2QVckJkDf5WJMlnLf8aw=; b=hViA5vM5t+xhLC0vqARQ0MDF+g64fcwRmI9k4daCPtiJQSV5xyjC8yiijAYAJBRWH6 R3o1xADpzS7QV+r4pPEyqpuuhpKqrYLZS8EpumxuwUfk8gl4hnbtVnbY3RuBBcubVdjx qR2XhNQea7EvOwTKA/X2vLq3odd99EjhHo+Gk=
MIME-Version 1.0
In-Reply-To <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com>
References <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com>
Date Fri, 20 Jan 2012 23:10:44 +0000
Subject Re: Weird Loop Behaviour
From Arnaud Delobelle <arnodel@gmail.com>
To Yigit Turgut <y.turgut@gmail.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.4901.1327101047.27778.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1327101047 news.xs4all.nl 6982 [2001:888:2000:d::a6]:32815
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19173

Show key headers only | View raw


On 20 January 2012 20:47, Yigit Turgut <y.turgut@gmail.com> wrote:
> Hi,
>
> In the following code, I am trying to run "black" screen for 3 seconds
> and respectively 2 seconds "white" screen. Black routine takes 3
> seconds and white 2 seconds, 2 x black + white = 8 seconds which
> should be the expected value but when I run it I get black-white-black-
> white   instead of black-white-black. Couldn't figure out what is
> wrong thus sharing the code as well ;
>
> white = False
>     while(end<8.00):
>      end = time.time() - start
>      if white:
>       screen.fill((255, 255, 255))
>        time.sleep(2)
>      else:
>        screen.fill((0, 0, 0))
>        time.sleep(3)
>      white = not white
>      pygame.display.update()
>     pygame.quit()

This is cryptic.  You'd be better off with something like

black = 0, 0, 0
white = 255, 255, 255
for color, wait in (black, 3), (white, 2), (black, 3):
    screen.fill(color)
    pygame.display.update()
    time.sleep(wait)
pygame.quit()

-- 
Arnaud

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Weird Loop Behaviour Yigit Turgut <y.turgut@gmail.com> - 2012-01-20 12:47 -0800
  Re: Weird Loop Behaviour MRAB <python@mrabarnett.plus.com> - 2012-01-20 21:10 +0000
  Re: Weird Loop Behaviour Emile van Sebille <emile@fenx.com> - 2012-01-20 13:20 -0800
  Re: Weird Loop Behaviour Arnaud Delobelle <arnodel@gmail.com> - 2012-01-20 23:10 +0000

csiph-web