Printing without newlines.. 
Author Message
 Printing without newlines..

I'm fooling with a little experiment and have run into
what I think is a simple problem... I'm not even sure if my
concept is sound, but my current problem is simple... Really...
I think... ;-)

I'm trying to get multiple characters of a string to print out
next to each other without spaces or newlines.  The plan is to
use non-parsed headers in a CGI script and put a brief delay
after each character in order to give a 1200 baud effect.  
To see the page I want to apply this too check out                

                  http://www.*-*-*.com/

so we start with...

line = "spamandeggs"
while f < y:
     print line[f:1]
     f = f + 1

results in

s
p
a
m
...

if we do  "print line[f:1],"

we get..

s p a m ...

"print line[f:1] +" of course gives an error.

I want...

spam...

how do I prevent a newline after each print?

I'm used to being able to do something like "print line[f:1];" but this
isn't going to work in Python.  I couldn't find anything in the
documentation I have that told how to do this...

Hmmmmmmmmm.....
-Sean


Network/Telecommunications Mgr
Information Resources Dept.
Shepard Poorman Communications Corp.
7301 North Woodland Drive, Indpls, IN  46268
(317) 293-1500    -WWW--> http://www.*-*-*.com/



Sun, 07 Jun 1998 03:00:00 GMT  
 Printing without newlines..

Quote:
> I'm trying to get multiple characters of a string to print out
> next to each other without spaces or newlines.  

Use sys.stdout.write() instead of print.

--
Donald Beaudry                                Silicon Graphics
U.I. Technology/DMS                           1 Cabot Road

                  "So much code, so little time..."



Sun, 07 Jun 1998 03:00:00 GMT  
 Printing without newlines..

Quote:
> I'm fooling with a little experiment and have run into
> what I think is a simple problem... I'm not even sure if my
> concept is sound, but my current problem is simple... Really...
> I think... ;-)

> I'm trying to get multiple characters of a string to print out
> next to each other without spaces or newlines.  The plan is to
> use non-parsed headers in a CGI script and put a brief delay
> after each character in order to give a 1200 baud effect.  
> To see the page I want to apply this too check out                

>                   http://www.spcc.com/sean.html

> so we start with...

> line = "spamandeggs"
> while f < y:
>      print line[f:1]
>      f = f + 1

> results in

> s
> p
> a
> m
> ...

> if we do  "print line[f:1],"

> we get..

> s p a m ...

> "print line[f:1] +" of course gives an error.

> I want...

> spam...

> how do I prevent a newline after each print?

> I'm used to being able to do something like "print line[f:1];" but this
> isn't going to work in Python.  I couldn't find anything in the
> documentation I have that told how to do this...

How about:-

import sys
import time

def slow_print(str):
    for c in str:
        sys.stdout.write(c)
        sys.stdout.flush()
        time.sleep(0.25)

Martin

--
 _--_|\  Martin Chilvers,                        Voice: +61-7-3365-4310
/      * Research Scientist, Architectures Unit, Fax:   +61-7-3365-4311

      v  The University of Queensland, QLD 4072.



Sun, 07 Jun 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. print without newline?

2. print without newline

3. Print characters on one line without newline...???

4. PEP 259: Omit printing newline after newline

5. PEP 259: Omit printing newline after newline

6. WRITE without newline?

7. write(*,*) without newline

8. Strip newline without losing implied space

9. write without newline

10. regsub of carriage return and newline without string map

11. How to print Subtotal Without Printing Detail

12. Newline Suppression in Print

 

 
Powered by phpBB® Forum Software