By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

Turn off line wrap for lists?

P: n/a
_
(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

Jan 5 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Thu, 2007-01-04 at 17:01 -0800, _ wrote:
(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
Jan 5 '07 #2

P: n/a

_ wrote:
(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

Jan 5 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.