Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Need cleanup advice for multiline string

Reply
Thread Tools

Need cleanup advice for multiline string

 
 
Robert Dailey
Guest
Posts: n/a
 
      08-12-2009
On Aug 12, 9:41*am, Robert Dailey <rcdai...@gmail.com> wrote:
> On Aug 12, 9:09*am, exar...@twistedmatrix.com wrote:
>
>
>
>
>
> > On 01:27 pm, jeanmic...@sequans.com wrote:

>
> > >Simon Brunning wrote:
> > >>2009/8/11 Robert Dailey <rcdai...@gmail.com>:
> > >>>On Aug 11, 3:40 pm, Bearophile <bearophileH...@lycos.com> wrote:
> > >>>>There are gals too here.
> > >>>It's a figure of speech. And besides, why would I want programming
> > >>>advice from a woman? lol. Thanks for the help.

>
> > >>Give the attitudes still prevalent in our industry (cf
> > >><http://tinyurl.com/c5nqju> and many more), I'm sorry to say that I
> > >>don't think this is funny.
> > >Having someone present technical informations with porn content cannot
> > >be qualified as "prevalent in our industry". I would even dare to say
> > >this is the opposite, it is almost unique.
> > >I would also add that Robert was very far from this attitude, I
> > >consider his joke as a friendly tickle, not a male chauvinist
> > >aggression. I'm no women, but I'm sure they are as capable as me, not
> > >to say more, of making the distinction.

>
> > >It has been said this list is not very friendly to newbies, let's not
> > >make it hostile to gentle jokes (even those not funny) when thanking
> > >helpers.

>
> > It's lots of little things like this which combine to create an
> > environment which is less friendly towards women than it is towards
> > others. *You might read it as a joke, others might not. *Even if it is a
> > joke, it's in poor taste and doesn't really belong on python-list.

>
> > There's a difference between pointing out inappropriate behavior and
> > being unfriendly. *Hopefully Robert got help with his problem. *That's
> > what the list is here for. *Having accomplished that, it is not
> > unfriendly to ask him not to make disparaging comments, "jokes" or
> > otherwise, about groups of people.

>
> > Jean-Paul

>
> Hey everyone,
>
> I was actually joking about my remark, I was making fun of the fact
> that Bearophile took my figure of speech literally. I have worked with
> a lot of women in the past and they even use "guys" to refer to
> everyone in a room (When there were obviously other females in that
> room as well).
>
> On a more serious note, I do apologize to those offended by my remark.
> I realize that these things can be a touchy subject for some people. I
> expected more of a laid-back attitude from everyone. No need to be so
> serious all the time. I cannot completely doubt that there are logical
> women out there. I just haven't seen one yet. But that doesn't mean
> I'm a sexist.
>
> With my apology presented, I would like to propose that we end the
> discussion here. As I said, this is a very sensitive subject and this
> thread could spin way out of control if we don't just ignore the
> issue. For those that took it as a friendly, harmless joke, hopefully
> you had a laugh. For those that took it seriously or as an offense,
> please take my apology to heart. Thanks once again to everyone for
> your help. I've long been a member of this community and I really
> appreciate the continuous support I've been receiving!
>
> Take care everyone!


Oh, one last thing... So everyone knows, I chose the following
formatting solution to multiline strings:

def MyFunction():
multilineString = (
'This is a string that spans '
'multiple lines.'
)
print( multilineString )

I think this is as good as it is going to get for my personal needs.
However, I do not like having to put a space at the end of each
string. I've also done this in the past, which is slightly more ugly:

multilineString = (
'This is a string that spans',
'multiple lines.'
)
print( ' '.join( multilineString ) )

This will add the spaces between lines for you. However, in a
production quality application I would always have strings external to
the scripts and have an advanced localization system. However this is
useful for quick little scripts that I want to keep tidy.
 
Reply With Quote
 
 
 
 
Simon Forman
Guest
Posts: n/a
 
      08-12-2009
On Aug 12, 10:41*am, Robert Dailey <rcdai...@gmail.com> wrote:
> On Aug 12, 9:09*am, exar...@twistedmatrix.com wrote:
>
>
>
> > On 01:27 pm, jeanmic...@sequans.com wrote:

>
> > >Simon Brunning wrote:
> > >>2009/8/11 Robert Dailey <rcdai...@gmail.com>:
> > >>>On Aug 11, 3:40 pm, Bearophile <bearophileH...@lycos.com> wrote:
> > >>>>There are gals too here.
> > >>>It's a figure of speech. And besides, why would I want programming
> > >>>advice from a woman? lol. Thanks for the help.

>
> > >>Give the attitudes still prevalent in our industry (cf
> > >><http://tinyurl.com/c5nqju> and many more), I'm sorry to say that I
> > >>don't think this is funny.
> > >Having someone present technical informations with porn content cannot
> > >be qualified as "prevalent in our industry". I would even dare to say
> > >this is the opposite, it is almost unique.
> > >I would also add that Robert was very far from this attitude, I
> > >consider his joke as a friendly tickle, not a male chauvinist
> > >aggression. I'm no women, but I'm sure they are as capable as me, not
> > >to say more, of making the distinction.

>
> > >It has been said this list is not very friendly to newbies, let's not
> > >make it hostile to gentle jokes (even those not funny) when thanking
> > >helpers.

>
> > It's lots of little things like this which combine to create an
> > environment which is less friendly towards women than it is towards
> > others. *You might read it as a joke, others might not. *Even if it is a
> > joke, it's in poor taste and doesn't really belong on python-list.

>
> > There's a difference between pointing out inappropriate behavior and
> > being unfriendly. *Hopefully Robert got help with his problem. *That's
> > what the list is here for. *Having accomplished that, it is not
> > unfriendly to ask him not to make disparaging comments, "jokes" or
> > otherwise, about groups of people.

>
> > Jean-Paul

>
> Hey everyone,
>
> I was actually joking about my remark, I was making fun of the fact
> that Bearophile took my figure of speech literally. I have worked with
> a lot of women in the past and they even use "guys" to refer to
> everyone in a room (When there were obviously other females in that
> room as well).
>
> On a more serious note, I do apologize to those offended by my remark.
> I realize that these things can be a touchy subject for some people. I
> expected more of a laid-back attitude from everyone. No need to be so
> serious all the time. I cannot completely doubt that there are logical
> women out there. I just haven't seen one yet. But that doesn't mean
> I'm a sexist.


Oh my. And you were doing so well. You haven't seen a logical
woman? Perhaps you're blind because your eyes were torn out by a
raging marmoset?

Guess what? Thinking (or just saying) that /does/ mean you're a
sexist. (Even if it was just another "friendly, harmless joke".)




> With my apology presented, I would like to propose that we end the
> discussion here. As I said, this is a very sensitive subject and this
> thread could spin way out of control if we don't just ignore the
> issue. For those that took it as a friendly, harmless joke, hopefully
> you had a laugh. For those that took it seriously or as an offense,
> please take my apology to heart. Thanks once again to everyone for
> your help. I've long been a member of this community and I really
> appreciate the continuous support I've been receiving!
>
> Take care everyone!


 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      08-12-2009
On Wed, 12 Aug 2009 07:47:58 -0700, Robert Dailey wrote:

> On Aug 12, 9:41Â*am, Robert Dailey <rcdai...@gmail.com> wrote:

....
> > I was actually joking about my remark, I was making fun of the fact
> > that Bearophile took my figure of speech literally.


Keep in mind that the Internet is a global forum, and not everyone here
speaks English as a first language. I believe Bearophile is one of those.
Although his, or possibly her, English is excellent, it wouldn't surprise
me that (s)he would misinterpret "guys" as just referring to men. I'm a
native English speaker, and I would have done the same.


> > I have worked with
> > a lot of women in the past and they even use "guys" to refer to
> > everyone in a room (When there were obviously other females in that
> > room as well).


Yes, I've seen this myself, but it's still uncommon enough to surprise me
every time I see it.


> > On a more serious note, I do apologize to those offended by my remark.
> > I realize that these things can be a touchy subject for some people. I
> > expected more of a laid-back attitude from everyone. No need to be so
> > serious all the time. I cannot completely doubt that there are logical
> > women out there. I just haven't seen one yet.


That's okay, I haven't seen terribly many logical men out there either.


> Oh, one last thing... So everyone knows, I chose the following
> formatting solution to multiline strings:
>
> def MyFunction():
> multilineString = (
> 'This is a string that spans '
> 'multiple lines.'
> )
> print( multilineString )
>
> I think this is as good as it is going to get for my personal needs.
> However, I do not like having to put a space at the end of each
> string.


So put them at the beginning of the next line. It makes the space more
obvious, so it's clearer what you have done. That's what I sometimes do.


> I've also done this in the past, which is slightly more ugly:
>
> multilineString = (
> 'This is a string that spans',
> 'multiple lines.'
> )
> print( ' '.join( multilineString ) )



It's also less efficient, as it does the concatenation at runtime instead
of compile time. But for a small script, that's not likely to be a
problem worth worrying about.



--
Steven
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      08-12-2009
On Wed, 12 Aug 2009 08:11:43 -0700, Simon Forman wrote:

[quoting Robert Dailey]
>> I cannot completely doubt that there are logical
>> women out there. I just haven't seen one yet. But that doesn't mean I'm
>> a sexist.

>
> Oh my. And you were doing so well. You haven't seen a logical woman?
> Perhaps you're blind because your eyes were torn out by a raging
> marmoset?
>
> Guess what? Thinking (or just saying) that /does/ mean you're a sexist.
> (Even if it was just another "friendly, harmless joke".)


It was an incredibly insensitive thing for Robert to say, having just
been slapped for a previous insensitive "joke" about women. But still,
most people, male or female, *aren't* logical. I know I've never met
somebody who is entirely logical, of either sex, and I'm pretty sure I've
not met very many people who are even mostly logical. Vulcans we are not.
Does this mean I'm equally sexist against men *and* women? ("I'm not
biased, I hate everyone equally!" *wink*)

Hell, here I am, at 2am, defending somebody I don't know, for saying
something I don't approve of, against somebody who is saying something I
agree with, out of some sort of misguided sense of fairness. Logic? Ha,
what's logic got to do with it?



--
Steven
 
Reply With Quote
 
David Bolen
Guest
Posts: n/a
 
      08-12-2009
Robert Dailey <> writes:

> Hey guys. Being a C++ programmer, I like to keep variable definitions
> close to the location in which they will be used. This improves
> readability in many ways. However, when I have a multi-line string
> definition at function level scope, things get tricky because of the
> indents. In this case indents are serving two purposes: For syntax and
> actual text output. The tabs for function scope should not be included
> in the contents of the string. (...)


Personally I'm in the camp that something like this should be hoisted
out of the code path (whether to global scope, a dedicated message
module or configuration file is a design choice).

But if it's going to stay inline, one approach that can maintain some
of the attractive qualities of a triple quoted string is to make use
of the textwrap module:

import textwrap

def RunCommand( commandList ):
# ...
if returnCode:
failMsg = textwrap.dedent('''\
*************************************************
The following command returned exit code [{:#x}].
This represents failure of some form. Please review
the command output for more details on the issue.
------------
{}
*************************************************
''')

which removes any common leading whitespace (must be identical in terms
of any tabs/spaces).

This is still additional run-time processing, and most likely less
efficient than the joining of individual strings, but it does permit a
clean triple-quoted string so IMO is easier to read/maintain in the
source - providing the code indentation level doesn't get in the way
of the desired line length of the string. You can also choose to
dedent the string a bit (say to the level of "failMsg") if needed
without being forced all the way back to the left margin.

You can also combine textwrap.dedent with some of the other options if
where the strings are defined makes it nicer if they still have some
indentation (say in a global Python module). In that case, you'd most
likely just process them once when the module was imported, so any
inefficiency in textwrap.dedent is far less important.

-- David
 
Reply With Quote
 
Aahz
Guest
Posts: n/a
 
      08-17-2009
In article <461cc6f1-fc23-4bc7-a719->,
Robert Dailey <> wrote:
>
>It's a figure of speech. And besides, why would I want programming
>advice from a woman? lol. Thanks for the help.


Well, I'm sorry to see this, it means I was wrong about the lack of
sexism in the Python community. I encourage anyone who wants to improve
the situation to join the new diversity list:

http://mail.python.org/mailman/listinfo/diversity
--
Aahz () <*> http://www.pythoncraft.com/

"I saw `cout' being shifted "Hello world" times to the left and stopped
right there." --Steve Gonedes
 
Reply With Quote
 
Jean-Michel Pichavant
Guest
Posts: n/a
 
      08-17-2009
Grant Edwards wrote:
> On 2009-08-11, Bearophile <> wrote:
>
>> Robert Dailey:
>>
>>
>>> This breaks the flow of scope. Would you guys solve this
>>> problem by moving failMsg into global scope? Perhaps through
>>> some other type of syntax?
>>>

>> There are gals too here.
>>

>
> Straying a bit OT, but I find this particular issue rather
> fascinating.
>
> At least in the US, "guys" is now pretty much gender-neutral
> according to my casual research (mostly just paying attention
> to informal speach).
>
> Oddly, it still seems to be masculine when singular. Though one
> commonly hears a group of females addressed as "you guys" or
> refered to as "those guys", one never hears a single female
> referred to as "a guy" or "that guy".
>
> It is a bit tricky, however, since a phrase like "a group of
> guys" still seems to refer to just males since the word "guys"
> in that case is being applied individually to a plurality of
> persons rather being applied collectivelly to a single group --
> if that makes any sense.
>
> I've actually discussed this with a a number of female friends,
> and they almost all thought the term "gals" was condescending
> and actually preferred to be referred to collectively as
> "guys".
>
>

I'm no English native, but I already heard women/men referring to a
group as "guys", no matter that group gender configuration. It's even
used for group composed exclusively of women. Moreover it looks like a
*very* friendly form, so there is really nothing to worry about it.

Forms like:
"Hi guys", "You guys should do something...", "Come on guys..." are very
friendly and gender-neutral.

JM
 
Reply With Quote
 
Piet van Oostrum
Guest
Posts: n/a
 
      08-17-2009
>>>>> Simon Brunning <> (SB) wrote:

>SB> 2009/8/11 Robert Dailey <>:
>>> On Aug 11, 3:40*pm, Bearophile <bearophileH...@lycos.com> wrote:
>>>> There are gals too here.
>>>
>>> It's a figure of speech. And besides, why would I want programming
>>> advice from a woman? lol. Thanks for the help.


>SB> Give the attitudes still prevalent in our industry (cf
>SB> <http://tinyurl.com/c5nqju> and many more), I'm sorry to say that I
>SB> don't think this is funny.


seconded
--
Piet van Oostrum <>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email:
 
Reply With Quote
 
Paul Boddie
Guest
Posts: n/a
 
      08-17-2009
On 17 Aug, 19:23, Jean-Michel Pichavant <jeanmic...@sequans.com>
wrote:
>
> Are you suggesting this list reject part of the community regarding its
> sexual orientation, ethnicity, size, culture? If that was the case I'd
> like to know about it.


Careful: you probably meant to write "rejects", not "reject". That
changes the meaning of what you've written somewhat.

> I would really want to know how you'd guess my gender (could be some
> clue somewhere), my sexual orientation, my religion and so on.
> How can you reject someone regarding informations you don't have ?


Well, everyone can of course hide their actual identity on the
Internet, but when someone references a group of people with a
juvenile remark (if we are being charitable about the matter), it has
nothing to do with guessing the characteristics of individuals. The
whole excuse that anonymity defends against insults and harassment is
a bit like saying that slinging mud at everyone is acceptable as long
as everyone is encouraged to do it and nobody is wearing their nicest
clothes. And unless your idea of a Python-related conference is
something close to a fancy-dress event with everyone "in character" -
which would obviously limit the effectiveness of such an event - you
presumably understand that there is a genuine need for continuity
between interactions on and off the Internet. This somewhat undermines
your argument.

> That's the beauty of this mailing list, it has diversity, by design.


An explanation is needed here for this not to sound like
conversational padding.

> We even welcome people that mixes up joke with sexist aggression, not to
> mention how open minded we are )


Well, jokes actually need an amusing side, regardless of how
"edgy" ("juvenile" is typically the more accurate term) the joke-
teller is trying to be, and that was completely absent from the remark
in question. There's little room for error in communication over a
medium like this one, as I pointed out with your opening sentence. And
much as it probably upsets the "unfettered free speech" advocates, we
should be able to assert that "sexist aggression" is not acceptable
behaviour amongst those who seek to participate in our community.

Paul
 
Reply With Quote
 
Carl Banks
Guest
Posts: n/a
 
      08-17-2009
On Aug 17, 10:03*am, Jean-Michel Pichavant <jeanmic...@sequans.com>
wrote:
> I'm no English native, but I already heard women/men referring to a
> group as "guys", no matter that group gender configuration. It's even
> used for group composed exclusively of women. Moreover it looks like a
> *very* friendly form, so there is really nothing to worry about it.


I like how being very friendly means calling people after a guy who
tried to blow up the English Parliament.


Carl Banks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Building a multiline string lallous Python 5 02-08-2010 11:24 PM
How to match string end for a multiline string? Peng Yu Perl Misc 2 06-24-2008 02:32 AM
how to convert a multiline string to an anonymous function? Danny Shevitz Python 3 04-30-2008 02:23 PM
how to define a variable to hold a multiline text input in perl from html multiline textbox dale zhang Perl Misc 8 11-30-2004 06:53 AM
How to pass the Multiline text value in Request String Suresh Ponraj ASP General 0 05-28-2004 05:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57