Flushing sdtout
Olivier Dagenais
olivierS.dagenaisP at canadaA.comM
Fri Jul 7 14:35:21 EDT 2000
Do a blank raw_input, sort of like:
print 'Enter type of DRC to run from menu -->'
sys.stdout.flush ( )
selection = raw_input ( ' ' )
Also, you could write your own function:
def print_flush ( message ):
print message
sys.stdout.flush ( )
--
----------------------------------------------------------------------
Olivier A. Dagenais - Carleton University - Computer Science III
"Aaron Ginn" <aaron.ginn at motorola.com> wrote in message
news:sn4s61hl9t.fsf at motorola.com...
>
> Is there a simple way to flush stdout on every print statement similar
> to the $| variable in perl? Currently, I'm adding a
> sys.stdout.flush() statement after every single print statement in a
> script in order to write the run to a logfile, but I'd like to simply
> be able to tell python to do it after every print statement without
> explicitly telling it to.
>
> Also, how can I flush the string in an input statement to stdout
> before the input is provided by the user? For example, here is a
> code snippet:
>
> print '------------------------------'
> sys.stdout.flush()
> print ' Type of DRC run.'
> sys.stdout.flush()
> print '------------------------------'
> sys.stdout.flush()
> print '1) DRC (default)'
> sys.stdout.flush()
> print '2) Antenna DRC check'
> sys.stdout.flush()
> print 'q) quit'
> sys.stdout.flush()
>
> while 1:
> selection = raw_input('Enter type of DRC to run from menu --> ')
> sys.stdout.flush()
>
> This prints the following to stdout:
>
> ------------------------------
> Type of DRC run.
> ------------------------------
> 1) DRC (default)
> 2) Antenna DRC check
> q) quit
>
> Unfortunately, it does not print the string in the raw_input statement
> until the user has selected from the menu. Thus the output looks like
> this:
>
> 1
> Enter type of DRC to run from menu -->
>
> I want the string printed to stdout before the user has to make a
> selection. Is there a way to do this?
>
> Thanks,
> Aaron
>
> --
> Aaron J. Ginn Motorola SPS
> Phone: (480) 814-4463 SemiCustom Solutions
> Fax: (480) 814-4058 1300 N. Alma School Rd.
> mailto:aaron.ginn at motorola.com Chandler, AZ 85226
More information about the Python-list
mailing list