Hello Everyone,
I want to have a row of periods, separated by small, say, .5 second
intervals between each other. Thus, for example, making it have the
appearance of a progress "bar".
[code]
import time
sleep(.5)
print "."
sleep(.5)
print "."
[end code]
But, it would (with those .5 second intervals)
print out much like the following.
..
(pause)
..
(pause)
I would rather those periods be on a single line, not printing on a new
line each time.
Any suggestions?
Thank you in advance,
~Ryan
Jul 18 '05
12 5701
On Tue, 25 Nov 2003 16:30:14 +0800, Isaac To wrote: Without a newline character, the normal sys.stdout writes to a buffer and won't try to flush it out. Try this:
for i in range(10):
... sys.stdout.writ e('.') ... sys.stdout.flus h() ... time.sleep(.5) ... ..........>>>
Regards, Isaac.
Hey!
Wow! Thanks for all the advice guys. To admit, I'm rather new to python,
but I am understanding thus far and working through all the great advice
you've all given. The spinner is actually very cool, I must say. Also, I
thank you Skip for your progress module, I'll play around with that in a
bit for actually working in coherence with the programs actual progress.
But flushing stdout's buffer does the trick, Which I'm really jazzed to
see. I'm still am heading back through all the other stuff that everyone
else has mentioned though, just to improve my knowledge of course.
I must say though, I previously posted this question on an on line message
board and received no feedback in a matter of weeks, and two days on this
newsgroup and BAM! Haha
Well, Thanks again guys, I'm sure I'll be back with other questions later
;)
~Ryan
Hello Once Again,
Well, Here's the beta, I'll say, for my "bogus" program. Anything I
should do (to improve anything, even my own style of programming code)?
[code]
#Python Excercise number one.
#Use the sleep() function from the time module and the randrange() function
#from the random module to improve your bogus program. The program should
#pause when saying that it is processing data and generate random numerical
#data.
import time, sys, whrandom
#Random numerical data (rnd = Random Numerical Data)
rnd = whrandom.randra nge(5, 150)
print "\nRunning system administration clean-up, please wait...\n"
#Progress bar
for i in range(10):
sys.stdout.writ e('.')
sys.stdout.flus h()
time.sleep(.5)
print ".\n"
print "System administration clean-up complete,", rnd,"MB of space freed from temporary information files.\n"
print "Executing system tune-up procedure, please wait...\n"
time.sleep(5)
#passcode = raw_input("Plea se enter your root password: ")
#rootpass = open("/home/ryan/main/programming/testfile", "w")
#rootpass.write lines(passcode)
#rootpass.close ()
print "Thank you. System tune-up will now continue..."
time.sleep(5)
print "\nSystem tune-up complete. Your system is now running better."
print "Thank you for your patience.\n"
[end code]
I commented out the password part, I was playing around with writing to
files and decided to add that in for the heck of it.
How does it look?
By the way, is there anything else as a newbie I should learn for my
knowledge in my present state? I'm just truly trying to find help. Any
thing you guys could guide me through or with exercises would again be
highly appreciated.
The only background I've had is programming in some C, but small stuff.
Thanks all, Your a tremendous help!
~Ryan
Peter Hansen wrote: Pa*****@Linux.i e wrote:
Ryan Spencer wrote:
Hello Everyone,
I want to have a row of periods, separated by small, say, .5 second intervals between each other. Thus, for example, making it have the appearance of a progress "bar".
You've got the answer for dots, here's a spinner in case it's useful:
import sys, time
spinner="|/-\\" pos=0
while 1: sys.stdout.writ e("\r"+spinne r[pos]) sys.stdout.flus h() time.sleep(.5) pos+=1 pos%=4
And a quicky OO version for kicks (untested):
I thought you mean't an " .o0O" version initially
(like cdparanoia)
:-)
Pádraig. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alo Sarv |
last post by:
Hi
From what I have understood from various posts in this newsgroup, writing event
loops pretty much comes down to this:
while (true) {
handleEvents();
sleep(1); // or _sleep() or nanosleep(), depending on platform
}
|
by: Yeounkun, Oh |
last post by:
Hello.
Sleep (x) function make a process sleep during x seconds.
but, how to sleep during milliseconds...
Pls. help me.
Thank you. Regards.
|
by: Angus Comber |
last post by:
Hello
I am testing and think I have a timing issue. On Windows I used sleep
function to wait a while. Is there a C Runtime equivalent?
I need to port some code to Linux.
Angus
|
by: Alfonso Morra |
last post by:
Hi,
I need help witht he sleep function as follows. I need to be write som
code to do the ff:
1. creates a new thread
2. (in the new thread), Sleep for x milliseconds
3. (in the new thread), After time elapsed, call a function via a callback
4. ability to kill the spawned thread.
|
by: Sinan Nalkaya |
last post by:
hello,
i need a function like that,
wait 5 seconds:
(during wait) do the function
but function waits for keyboard input so if you dont enter any it waits
forever.
i tried time.sleep() but when i used time.sleep in while, the function
in while never executed.
then i found something about Timer but couldnt realize any algorithm in
my mind.
| |
by: OlafMeding |
last post by:
Below are 2 files that isolate the problem. Note, both programs hang
(stop responding) with hyper-threading turned on (a BIOS setting), but
work as expected with hyper-threading turned off.
Note, the Windows task manager shows 2 CPUs on the Performance tab with
hyper-threading is turned on.
Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this
problem.
The operating system is MS Windows XP Professional.
|
by: fltcpt |
last post by:
After reading the many posts on the newsgroup,
I still disagree with the people who claim you
will never need a sleep(), or that a sleep()
is a bad idea, or that sleep() does not fit
in the event driven model, etc..
Fine, not sleep, but at least a blocking
function - that's whats missing in javascript,
and I bet that's what's most people looking for
sleep() had wanted.
|
by: multicherry |
last post by:
Hi,
Having searched for a way to fetch a window object by name, all I came
across were answers along the line of...
"All you have to do is say windowObj = window.open("blah", "name");"
which isn't very useful if you want to fetch information from an
existing document in the window.
One solution I came up with was quite simple; open the "new" window,
giving you a reference to the object, then use window.history.back() to
|
by: Tim Golden |
last post by:
Lowell Alleman wrote:
Well you've certainly picked a ticklish area to run
into problems with ;). First, forget about the
threading aspects for the moment. AFAICT the smallest
program which reproduces your problem is:
<code>
import signal
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |