473,414 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

goto, cls, wait commands

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.
Jul 18 '05 #1
25 4567
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)
Jul 18 '05 #2
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)
Jul 18 '05 #3
On Thu, 10 Feb 2005 16:59:04 +0100, rumours say that BOOGIEMAN
<BO*********@YAHOO.COM> 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...
Jul 18 '05 #4
On 2005-02-10, BOOGIEMAN <BO*********@YAHOO.COM> 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
Jul 18 '05 #5
[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, "goto"s 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.


Ahhhhhh, a simple question! :-)

import time
time.sleep(10.0)

HTH,

--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan
Jul 18 '05 #6
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... !-)
bruno@bibi modulix $ cls
-bash: cls: command not found

Bad luck ! didn't work !-)

Bruno
Jul 18 '05 #7
Grant Edwards a écrit :
On 2005-02-10, BOOGIEMAN <BO*********@YAHOO.COM> 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 !-)
Jul 18 '05 #8
On 2005-02-10, Bruno Desthuilliers <bd*****************@free.quelquepart.fr> wrote:
Grant Edwards a écrit :
On 2005-02-10, BOOGIEMAN <BO*********@YAHOO.COM> 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.com CORDUROY SOAP DISH!!
Jul 18 '05 #9
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... !-)
bruno@bibi 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-)
Jul 18 '05 #10
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... !-)
bruno@bibi 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-)

Jul 18 '05 #11
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 ?

Jul 18 '05 #12
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

Jul 18 '05 #13
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

Jul 18 '05 #14
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
Jul 18 '05 #15
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.

Jul 18 '05 #16
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").

Jul 18 '05 #17
"BOOGIEMAN" <BO*********@YAHOO.COM> a écrit dans le message de
news:1i*****************************@40tude.net...
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
Jul 18 '05 #18
Grant Edwards <gr****@visi.com> 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 <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Jul 18 '05 #19
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

Jul 18 '05 #20

"Jeff Shannon" <je**@ccvcorp.com> a écrit dans le message de
news:11*************@corp.supernews.com...
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


The automated translations are very commonly used actually in computing
industry. If you want an overview, you can try "legacy migration" in google
for instance (or "as400 automated migration" or anything of that kind).
Translate a computer's language is not the same at all than to translate a
human language. In the first case, you have a good chance to know all the
rules. Even if the work is not perfect, it can offer you a chance to
continue to use a 10000 programs application without having to rewrite all
(several years of work indeed).
The last time I did that, I converted arround 6000 cobol programs in a
couple of months, which is obviously not possible by hand (thanks to python
;-). And it was not possible to remove GOTO, because that would really need
to rewrite manually the programs, that means to entirely redo the
application (probably a 20 human years work !).

Regards,
jm
Jul 18 '05 #21
"jean-michel" <no****@nospam.fr> 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>

Jul 18 '05 #22
Alan Kennedy <al****@hotmail.com> 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 <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #23
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>

Jul 18 '05 #24
At least I thought this was funny and cool! -Erik

Jul 18 '05 #25
You sir are a troll for sure. QBasic?! When was the last time you did
any programming, 1989? Gave me a laugh though.

Lars

Jul 18 '05 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Philip Smith | last post by:
I've read with interest the continuing debate about 'lambda' and its place in Python. Just to say that personally I think its an elegant and useful construct for many types of programming task...
3
by: Tim Stokes | last post by:
Hello all, Is it possible to make an asp script 'wait' inbetween commands? A quick example (but not what I've got in mind): Response.write ("Please wait. Validating password...") ...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
24
by: sureshjayaram | last post by:
In some functions where i need to return multiple error codes at multiple places, I use multiple return statements. Say for ex. if (Found == 1) { if (val == -1) return error1; } else { if...
6
by: eBob.com | last post by:
How do you make a loop iterate early without using a GoTo? (I guess I've done too much structured programming and I really don't like using GoTos.) Here's my code ... For Each Thing As OFI...
5
by: BF | last post by:
Hi, I have a problem: I am writing an update script for a database and want to check for the version and Goto the wright update script. So I read the version from a table and if it match I...
3
by: memyselfandmiah | last post by:
I am in a cpp class, but i am messing around the program on my own, and I am looking for some commands. or at least a place that i can go to find commands that i want. There are 2 questions that...
19
by: David Given | last post by:
I have a situation where I need to use GOTO in a Javascript program. No, I can't use break or continue. Yes, I really do know what I'm doing. What I've got is a huge mass of automatically...
59
by: raashid bhatt | last post by:
why are GOTO's not used they just a simple JMP instructions what's bad about them
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.