print format
Curtis Jensen
cjensen at bioeng.ucsd.edu
Wed Jul 26 12:04:47 EDT 2000
William Tanksley wrote:
>
> On Tue, 25 Jul 2000 17:47:44 -0700, Curtis Jensen wrote:
> >I don't know if this is possible in python but, Is there a way to repeat
> >a format command a spceified number of times? For example, in Fortran
> >there is the format code "20I5" Which is the same as "I5" twenty
> >times. I want something like:
> >print '20(%i5) ' % [list of 20 intgers]
>
> Perhaps
>
> print (20*"%5i ") % [list of 20 integers]
>
> will work for you. The multiplier on the string repeats it 20 times.
> This lets you do things like:
>
> list = [list of 'n' integers]
> print (len(list)*"%5i ") % list
This only works with tuples, not lists. The % operator with strings
requires tuples. I'm not sure why the chose to make this limitation.
The following code gives this error.
a = [1,2,3,4,5]
print (5*"%5i ") % a
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: illegal argument type for built-in operation
However, it works fine if a is a tuple.
Thanks.
>
> >Also, how do I print without a new line other than using
> >sys.stdout.write?
>
> Why? Is there something in specific you're trying to avoid? (Yes, it's
> possible, but it's not pretty.)
I want to print something, and then latter, print something else on the
same line. I don't want to append to a string and then print the
string.
--
Curtis Jensen
cjensen at bioeng.ucsd.edu
http://www-bioeng.ucsd.edu/~cjensen/
FAX (425) 740-1451
More information about the Python-list
mailing list