More
Alex Martelli
aleax at aleax.it
Thu Apr 17 13:53:47 EDT 2003
kpop wrote:
> Hi
> I usualy print strings the normal way
> print x, but if the string is too big it will
> go by the screen too fast and i wont be
> able to see anything. I notice the python
> internel help system hasa thing like the
> unix prgram more, where you press enter
> to go down. How can i use that in my own
> programs? Is there a function or a module.
> I am using windows so i dont have more.
> Thanks
>
> reposted because i got the date wrong last time
Perhaps
import pydoc
pydoc.pager(thelongstring)
comes close to doing what you want. However,
that will only help you if thelongstring has
many LINES, not necessarily if it's e.g. just
one line of humungous length (as pydoc itself
doesn't need to struggle with that...). I
cannot think, offhand, of a builtin way to
solve that problem -- normally, Python's own
formatting tools wouldn't break strings except
at word boundaries, which might not be enough
for you. If you do observe this problem and
can't find a built-in solution for it, then
it's not hard to program one yourself, of
course, e.g. (warning, untested):
def splitby(s, L=78):
lines = []
while s:
lines.append(s[:L])
s = s[L:]
return '\n'.join(lines)
Alex
More information about the Python-list
mailing list