Turn off line wrap for lists?

?

_

(I did google for this, I promise)

How do I get python NOT to insert newlines into string representations
of lists when I do something like this:

strCollector += "%s" % (['a', 'list', 'with', 'lots', 'of', 'elements']
* 100)

?

I would like to set a default never to do this, if possible. (Never mix
formatting with display, or tequila with bourbon -- bad, bad, bad!)

FYI I am using this to export data into tab delimited format, so the
lines can be as long as they need to be, but a newline means a new
record.

FYI (2), this is in web application too, so I am afraid I might have to
set the default in a bunch of different modules.

TIA
 
C

Carsten Haese

(I did google for this, I promise)

How do I get python NOT to insert newlines into string representations
of lists when I do something like this:

strCollector += "%s" % (['a', 'list', 'with', 'lots', 'of', 'elements']
* 100)

What makes you think that that inserts newline characters? My python
doesn't do that:
a = "%s" % (['a', 'list', 'with', 'lots', 'of', 'elements'] * 100)
"\n" in a
False

FYI I am using this to export data into tab delimited format

You could avoid reinventing the wheel by using the "csv" module.

-Carsten
 
M

Michael Tobis

_ said:
(I did google for this, I promise)

How do I get python NOT to insert newlines into string representations
of lists when I do something like this:

strCollector += "%s" % (['a', 'list', 'with', 'lots', 'of', 'elements']
* 100)

It shouldn't and doesn't insert newlines.

######
strCollector = "%s" % (['a', 'list', 'with', 'lots', 'of', 'elements'] * 100)
strCollector.split("\n")[0] == strCollector
True
######
mt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top