Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dennis Lee Bieber Newsgroups: comp.lang.python Subject: Re: GoPiGo script Date: Mon, 02 Nov 2015 09:10:17 -0500 Organization: IISS Elusive Unicorn Lines: 34 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 452VRndk8AkLWowN5dRboQzXkY4D6m8wpZkhTAS9B54w== Return-Path: 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; 'executed': 0.07; 'exit.': 0.09; 'loop.': 0.09; 'message-id:@4ax.com': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'subject:script': 0.09; 'python': 0.10; 'def': 0.13; '(but': 0.15; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'script.': 0.18; 'url:home': 0.18; 'language': 0.19; '2015': 0.20; 'do.': 0.22; 'defined': 0.23; 'tried': 0.24; 'mon,': 0.24; 'header:X-Complaints-To:1': 0.26; 'executing': 0.27; 'function': 0.28; 'indentation': 0.29; 'restart': 0.29; 'print': 0.30; 'focusing': 0.33; 'nov': 0.35; 'something': 0.35; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'charset :us-ascii': 0.37; 'end': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'called': 0.40; 'your': 0.60; '>def': 0.84; '>if': 0.84; 'manual,': 0.84; 'dennis': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: adsl-108-68-178-61.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98101 On Mon, 02 Nov 2015 13:29:04 GMT, input/ldompeling@casema.nl declaimed the following: >I tried to use def loop(): now for to restart the script. >but its only restart "fwd()" print ("forward 1x") and then stop. >def loop(): > fwd() > print ("forward 1x") > time.sleep(2) > stop() > >if mindist > us_dist(15): Which is exactly what you told it to do. You have defined a function containing four statements: fwd(), print(), sleep(), and stop(); after executing the stop the function will return to where it was called -- the end of your program. All of your"if" statements will be executed after "loop" is defined (but not executed) and before the call to "loop" at the bottom. They are NOT part of "loop". Please reread the Python language reference manual, focusing on the part that describes indentation and block structuring. >loop() > Also, just calling something "loop" does not make it a loop. This function will be called just one time and then the program will exit. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/