472,127 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Re: Need formatting suggestion for long strings

On Fri, 5 Sep 2008 14:24:16 -0500, Robert Dailey <rc******@gmail.comwrote:
>Hi,

I find quite often that I'm writing things like this:

raise FatalExcept( "Insufficient number of arguments specified. Exactly {0}
arguments are required. See stage.bat for documentation on accepted
parameters.".format( num_arguments ) )

On my display (Vertical monitor), this exceeds the width of my display, and
to view the entire length of the string I am forced to pan my view left and
right. Is there a special way I can format this string so that it fits
nicely on the screen? Keep in mind that one important factor is that
whitespace is very sensitive, and I do not want line breaks in my script
file to become part of the string itself. I like how C++ handles strings,
like this:

char const* mystring =
"This is a very long string that "
"spans multiple lines and does "
"not include line breaks or tabs "
"from the source file between "
"the strings partitions."
What do you guys prefer? Thanks for reading.
mystring = (
"This is a very long string that "
"spans multiple lines and does "
"not include line breaks or tabs "
"from the source file between "
"the strings partitions.")

Jean-Paul

Sep 5 '08 #1
2 1519
aha
On Sep 5, 3:29*pm, Jean-Paul Calderone <exar...@divmod.comwrote:
On Fri, 5 Sep 2008 14:24:16 -0500, Robert Dailey <rcdai...@gmail.comwrote:
Hi,
I find quite often that I'm writing things like this:
raise FatalExcept( "Insufficient number of arguments specified. Exactly {0}
arguments are required. See stage.bat for documentation on accepted
parameters.".format( num_arguments ) )
On my display (Vertical monitor), this exceeds the width of my display, and
to view the entire length of the string I am forced to pan my view left and
right. Is there a special way I can format this string so that it fits
nicely on the screen? Keep in mind that one important factor is that
whitespace is very sensitive, and I do not want line breaks in my script
file to become part of the string itself. I like how C++ handles strings,
like this:
char const* mystring =
* *"This is a very long string that "
* *"spans multiple lines and does "
* *"not include line breaks or tabs "
* *"from the source file between "
* *"the strings partitions."
What do you guys prefer? Thanks for reading.

mystring = (
* * "This is a very long string that "
* * "spans multiple lines and does "
* * "not include line breaks or tabs "
* * "from the source file between "
* * "the strings partitions.")

Jean-Paul
Can you be more specific? What is the formatting criteria? Are you
talking about formatting the string for display or are you talking
about the source?
Sep 5 '08 #2
I'm concerned about the formatting of the string in that I do not want the
way I split the string up in source code to affect the way the string is
displayed to the console. In other words, in source, if I break up a single
string into multiple lines (using carriage returns), I would expect the
string to still render as a single-line string.

I'm also concerned about the source formatting, because I do not want the
single-line string to run off the edge of my display. I want it to be in
"Paragraph form" in the source code, but remain a single-line when printed.
I think you can also escape the line breaks:
>>mystring = (
.... "This is a very long string that "
.... "spans multiple lines and does "
.... "not include line breaks or tabs "
.... "from the source file between "
.... "the strings partitions.")
>>mystring2 = 'This is a very long string that spans multiple lines and does not include line breaks or tabs from the source file between the strings partitions.'
mystring == mystring2
True
>>mystring3 = 'This is a very long string that \
.... spans multiple lines and does not include line breaks \
.... or tabs from the source file between the strings \
.... partitions.'
>>mystring3 == mystring
True
Sep 5 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Al Newton | last post: by
4 posts views Thread by hope | last post: by
4 posts views Thread by Robert Manookian | last post: by
4 posts views Thread by | last post: by
1 post views Thread by george | last post: by
9 posts views Thread by pic078 via AccessMonster.com | last post: by
6 posts views Thread by Tomasz J | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.