Re: goto, cls, wait commands
Erik Bethke wrote: At least I thought this was funny and cool! -Erik Thanks. ;) -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Mike Meyer wrote: Secondly, how do I clear screen (cls) from text and other content ? That depends on A: What type of display device you're using B: What type of interface is being rendered on that display (command line, GUI, IDE, etc) C: Perhaps what operating system you are using. D: Whether or not you have a display device at all. I run Python scripts from Cron whose sole output functionality is via email. I run Python scripts as daemons whose sole output functionality is syslog. are you the original poster? if so, can you explain why you asked how to clear the screen if you don't have a screen? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
You sir are a troll for sure. QBasic?! When was the last time you did any programming, 1989? Gave me a laugh though. Lars -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
jean-michel [EMAIL PROTECTED] wrote: And it was not possible to remove GOTO, because that would really need to rewrite manually the programs really? converting GOTO messes to structured programs has been a solved problem for many years (you can buy commercial products that does this, and I don't think they come with programmers in the box) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Alan Kennedy [EMAIL PROTECTED] writes: Secondly, how do I clear screen (cls) from text and other content ? That depends on A: What type of display device you're using B: What type of interface is being rendered on that display (command line, GUI, IDE, etc) C: Perhaps what operating system you are using. D: Whether or not you have a display device at all. I run Python scripts from Cron whose sole output functionality is via email. I run Python scripts as daemons whose sole output functionality is syslog. Clear screen doesn't make sense in thsoe two contexts. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Harlin wrote: No goto needed. If this makes no sense (which it may not if all you've been exposed to is BASIC) it wouldn't be a bad idea to Google why you should never use a goto statement. GOTO isn't even needed in QBasic (except for ON ERROR GOTO). -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
BOOGIEMAN [EMAIL PROTECTED] a écrit dans le message de news:[EMAIL PROTECTED] I've just finished reading Python turtorial for non-programmers and I haven't found there anything about some usefull commands I used in QBasic. First of all, what's Python command equivalent to QBasic's goto ? Secondly, how do I clear screen (cls) from text and other content ? And last, how do I put program to wait certain amount of seconds ? If I remeber correctly I used to type Wait 10 and QBasic waits 10 seconds before proceeding to next command. Hi all, I saw a lot of comments saying GOTO is not usefull, very bad, and we should'nt use it because we don't need it. I think that's true, but only if you *create* programs. But if the goal is to provide some kind of converter to automatically take an old application written with an old language (using GOTO), and generating python code, it would certainly a great help to have this (unclean) feature in native python. Best regards jm -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Grant Edwards [EMAIL PROTECTED] wrote: I forgot to mention try/except. When I do use goto in C programming it's almost always to impliment what would have been a try/except block in Python. Yes I'd agree with that. No more 'goto out'. There is this also for (i = 0; ...) { if (something) goto found; } /* do stuff when not found */ found:; (yes I hate setting flags in loops ;-) This translates exactly to the for: else: construct for i in xrange(...): if something: break else: # do stuff when not found The last language I saw with this very useful feature was FORTH in about 1984! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
jean-michel wrote: Hi all, I saw a lot of comments saying GOTO is not usefull, very bad, and we should'nt use it because we don't need it. I think that's true, but only if you *create* programs. But if the goal is to provide some kind of converter to automatically take an old application written with an old language (using GOTO), and generating python code, it would certainly a great help to have this (unclean) feature in native python. But an automatic translator is certain to be imperfect. One can no more translate mechanically between computer languages than one can translate mechanically between human languages -- and we've all seen the fun that can be had by machine-translating from language A - language B - language A, right? What do you think the effect of that sort of meaning-drift would be on application code? In other words, any translation from one language to another will require significant human attention, by someone familiar with both languages, to ensure that the original meaning is preserved as close as possible. You're going to have to rewrite chunks of code by hand no matter what you do; it'd be silly to *not* take that opportunity to purge things like GOTO. Jeff Shannon Technician/Programmer Credit International -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
BOOGIEMAN a écrit : I've just finished reading Python turtorial for non-programmers and I haven't found there anything about some usefull commands I used in QBasic. First of all, what's Python command equivalent to QBasic's goto ? I had a professor that told me that using goto in prog is that there is a mistake in the algorythm. If I remember, I think there is no goto instruction in python ! Secondly, how do I clear screen (cls) from text and other content ? I don't understand well what you exactly want to do. Can you explain more please. And last, how do I put program to wait certain amount of seconds ? If I remeber correctly I used to type Wait 10 and QBasic waits 10 seconds before proceeding to next command. import time time.sleep(10) -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
BOOGIEMAN wrote: I've just finished reading Python turtorial for non-programmers and I haven't found there anything about some usefull commands I used in QBasic. First of all, what's Python command equivalent to QBasic's goto ? There isn't one. Why do you think you need this? Secondly, how do I clear screen (cls) from text and other content ? That depends on your computer, and how you are running your program. One way which *might* work is: import os os.system(cls) And last, how do I put program to wait certain amount of seconds ? If I remeber correctly I used to type Wait 10 and QBasic waits 10 seconds before proceeding to next command. import time time.sleep(10) -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
On Thu, 10 Feb 2005 16:59:04 +0100, rumours say that BOOGIEMAN [EMAIL PROTECTED] might have written: Best advice: try to forget QBasic, and try again reading the tutorial. That, if your post is serious. If it isn't, keep reading my reply :) I've just finished reading Python turtorial for non-programmers and I haven't found there anything about some usefull commands I used in QBasic. First of all, what's Python command equivalent to QBasic's goto ? goto for python: http://entrian.com/goto/index.html Please ignore the line in bold red. Secondly, how do I clear screen (cls) from text and other content ? Python clears after itself, so you don't need to. If you insist though, . import os . os.system('cls') That on a windows console. If on IDLE, try closing the window and reopening it. And last, how do I put program to wait certain amount of seconds ? If I remeber correctly I used to type Wait 10 and QBasic waits 10 seconds before proceeding to next command. (A serious answer for a change) Waiting is time related. So import time and call the time.sleep function. Try entering help at a Python prompt. -- TZOTZIOY, I speak England very best. Be strict when sending and tolerant when receiving. (from RFC1958) I really should keep that in mind when talking with people, actually... -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
On 2005-02-10, BOOGIEMAN [EMAIL PROTECTED] wrote: First of all, what's Python command equivalent to QBasic's goto ? There isn't one. One defines functions and calls them. One uses for and while loops. One uses list comprehensions. One uses if/elif/else. Secondly, how do I clear screen (cls) from text and other content ? That depends on the host system. Under Unix, you can do os.system('clear'). Or you can use ncurses. Or you can use os.system to run the 'tput' command with appropriate parameters -- see the tput man page. There's probably some way to do it in Windows as well, but I don't do windows. And last, how do I put program to wait certain amount of seconds ? time.sleep(1) will wait for 1 second. time.sleep(5.5) will wait for 5.5 seconds. -- Grant Edwards grante Yow! Yow! I like my new at DENTIST... visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
[BOOGIEMAN] I've just finished reading Python turtorial for non-programmers and I haven't found there anything about some usefull commands I used in QBasic. First of all, what's Python command equivalent to QBasic's goto ? Oh no! You said the G word! That's a dirty word in computer science circles, because of the perception that goto (there, I said it, ugh!) can lead people to structure their code badly, i.e. write bad programs. Instead, most modern programming languages offer a range of control and looping constructs that allow you to code your intention more clearly than with goto. Python examples include while, for .. in .., try .. except .., etc, etc. So in order to answer your question, you're probably going to have to be more specific on what you want goto for. Interestingly, gotos are undergoing a bit of renaissance in coding circles, but people have felt compelled to call them something different: continuations. But you're probably not interested in them. And python can't do them anyway. Secondly, how do I clear screen (cls) from text and other content ? That depends on A: What type of display device you're using B: What type of interface is being rendered on that display (command line, GUI, IDE, etc) C: Perhaps what operating system you are using. And last, how do I put program to wait certain amount of seconds ? If I remeber correctly I used to type Wait 10 and QBasic waits 10 seconds before proceeding to next command. Ahh, a simple question! :-) import time time.sleep(10.0) HTH, -- alan kennedy -- email alan: http://xhaus.com/contact/alan -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Duncan Booth a écrit : BOOGIEMAN wrote: (snip) Secondly, how do I clear screen (cls) from text and other content ? That depends on your computer, and how you are running your program. One way which *might* work is: import os os.system(cls) *might* work... !-) [EMAIL PROTECTED] modulix $ cls -bash: cls: command not found Bad luck ! didn't work !-) Bruno -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Grant Edwards a écrit : On 2005-02-10, BOOGIEMAN [EMAIL PROTECTED] wrote: First of all, what's Python command equivalent to QBasic's goto ? There isn't one. One defines functions and calls them. One uses for and while loops. One uses list comprehensions. One uses if/elif/else. and even sometimes break, continue, and return !-) -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
On 2005-02-10, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Grant Edwards a écrit : On 2005-02-10, BOOGIEMAN [EMAIL PROTECTED] wrote: First of all, what's Python command equivalent to QBasic's goto ? There isn't one. One defines functions and calls them. One uses for and while loops. One uses list comprehensions. One uses if/elif/else. and even sometimes break, continue, and return !-) I forgot to mention try/except. When I do use goto in C programming it's almost always to impliment what would have been a try/except block in Python. -- Grant Edwards grante Yow! ... the MYSTERIANS at are in here with my visi.comCORDUROY SOAP DISH!! -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
Bruno Desthuilliers wrote: Duncan Booth a écrit : BOOGIEMAN wrote: Secondly, how do I clear screen (cls) from text and other content ? That depends on your computer, and how you are running your program. One way which *might* work is: import os os.system(cls) *might* work... !-) [EMAIL PROTECTED] modulix $ cls -bash: cls: command not found Bad luck ! didn't work !-) Works for me! But then again... kairos:ug cat cls #! /usr/local/bin/python print \xc, /ug 8-) -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
import os if os.name == nt: os.system(cls) # Works in w2k else: os.system(clear)# Works in cygwin's Bash Ulf Göransson wrote: Bruno Desthuilliers wrote: Duncan Booth a écrit : BOOGIEMAN wrote: Secondly, how do I clear screen (cls) from text and other content ? That depends on your computer, and how you are running your program. One way which *might* work is: import os os.system(cls) *might* work... !-) [EMAIL PROTECTED] modulix $ cls -bash: cls: command not found Bad luck ! didn't work !-) Works for me! But then again... kairos:ug cat cls #! /usr/local/bin/python print \xc, /ug 8-) -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
OK, thanks all Here's presentation of my advanced programming skills :) import os import time os.system(cls) number = 78 guess = 0 while guess != number: guess = input(Guess number: ) if guess number: print Lower time.sleep(3) os.system(cls) elif guess number: print Higher time.sleep(3) os.system(cls) print That's the number ! --- BTW, I'm thinking to replace lines time.sleep(3) with something like Press any key to guess again How do I do that ? Also I wanted to put at the end something like Do you want to guess again ? and then GOTO start of program, but since there is no such command in Python what are my possible solutions ? -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
BOOGIEMAN said unto the world upon 2005-02-10 16:06: OK, thanks all Here's presentation of my advanced programming skills :) import os import time os.system(cls) number = 78 guess = 0 while guess != number: guess = input(Guess number: ) if guess number: print Lower time.sleep(3) os.system(cls) elif guess number: print Higher time.sleep(3) os.system(cls) print That's the number ! --- BTW, I'm thinking to replace lines time.sleep(3) with something like Press any key to guess again How do I do that ? Also I wanted to put at the end something like Do you want to guess again ? and then GOTO start of program, but since there is no such command in Python what are my possible solutions ? Hi, I'm no expert and I owe much of whatever I know to the Python Tutor list. I'd suggest you check it out http://mail.python.org/mailman/listinfo/tutor. As for your situation, I'd do something like this untested code: guess = input(Guess number: ) while guess != number: print `Nope.' guess = raw_input('Guess again? (Enter q for quit)') if guess.lower() == 'q': # .lower() ensures 'Q' will match print `Quitter!' break if guess number: # stuff here if guess number: # different stuff here raw_input is safer than input as it prevents malicious code from ruining your day. A while loop is the usual way to repeat something until some condition is met. Here it repeats until guess == number. Another common idiom is while True: # do some stuff if some_condition: # some condition being True signals the break # need to break out of the loop I game to Python 10'ish years after I'd programmed some in BASIC and then not again. It took me a while to grok goto-less coding, too :-) HTH, Brian vdB -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
No goto needed. If this makes no sense (which it may not if all you've been exposed to is BASIC) it wouldn't be a bad idea to Google why you should never use a goto statement. To do a clear screen you'll need to use the method that your command shell uses. The shortcut to this is for Windows, 'cls' and Linux (and other Unix derivatives) is 'clear'. To put this into your programs you'll need to import the OS module. Then use the method, system() to run the command: import os os.system('cls') or os.system('clear') To do a 'wait' you can use the Time module. import time seconds = 10 #This is an integer value time.sleep(seconds) Only on Unix systems can you use the system command 'sleep'. However, in the name of portability it's better to use the Python modules whenever possible (they'll work on any system that supports Python). Hope it helps. Harlin -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
BOOGIEMAN wrote: First of all, what's Python command equivalent to QBasic's goto ? You can only use the goto function if you use Python with line numbers, thusly: 10 import sys 20 real_stdout = sys.stdout 30 class fake_stdout(object): pass 40 fake_stdout.write = lambda x, y: None 50 sys.stdout = fake_stdout() 60 import this 70 sys.stdout = real_stdout 80 d = {} 90 c = 65 100 i = 0 110 d[chr(i+c)] = chr((i+13) % 26 + c) 120 if i == 26: goto(150) 130 i += 1 140 goto(110) 150 if c == 97: goto(180) 160 c = 97 170 goto(100) 180 print How zen it is: 190 print .join([d.get(c, c) for c in this.s]) z = dict((int(x[0]), .join(x[1:])) for x in (y.split() for y in (__doc__ or _).strip().splitlines())); k = [0] + sorted(z.keys()); m = dict((b,a) for a,b in enumerate(k)); l = k[1] def goto(n): global l; l = k[m[n]-1] while l and l = k[-1]: exec z[l]; l = l != k[-1] and k[m[l]+1] -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: goto, cls, wait commands
On Windows, I use WConio http://newcenturycomputers.net/projects/wconio.html It provides other screen functions you might have gotten used to in QBasic as well. On unix/cygwin, use curses. I am not aware of any portable library though. I used to use cls a lot in my QBasic days. Now I just don't. -- http://mail.python.org/mailman/listinfo/python-list