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-11-2009
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. Below is the code I am trying to
improve. Notice how it looks ugly/unreadable because of the way the
string contents are shifted all the way to the left edge of the
document. 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?

Help is appreciated!

def RunCommand( commandList ):
commandString =
print( 'Running Command:', )
cmd = subprocess.Popen( commandList )
returnCode = cmd.wait()
if returnCode:
failMsg = '''\
*************************************************
The following command returned exit code [{:#x}].
This represents failure of some form. Please review
the command output for more details on the issue.
------------
{}
*************************************************
'''
commandString = ' '.join( commandList )
raise CommandFailure( failMsg.format( returnCode,
commandString ) )
 
Reply With Quote
 
 
 
 
Robert Dailey
Guest
Posts: n/a
 
      08-11-2009
On Aug 11, 3:08*pm, Robert Dailey <rcdai...@gmail.com> wrote:
> 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. Below is the code I am trying to
> improve. Notice how it looks ugly/unreadable because of the way the
> string contents are shifted all the way to the left edge of the
> document. 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?
>
> Help is appreciated!
>
> def RunCommand( commandList ):
> * *commandString =
> * *print( 'Running Command:', *)
> * *cmd = subprocess.Popen( commandList )
> * *returnCode = cmd.wait()
> * *if returnCode:
> * * * failMsg = '''\
> *************************************************
> The following command returned exit code [{:#x}].
> This represents failure of some form. Please review
> the command output for more details on the issue.
> ------------
> {}
> *************************************************
> '''
> * * * commandString = ' '.join( commandList )
> * * * raise CommandFailure( failMsg.format( returnCode,
> commandString ) )


And yes, I recognize there are syntax errors. Ignore those for now.
 
Reply With Quote
 
 
 
 
Mark Lawrence
Guest
Posts: n/a
 
      08-11-2009
Robert Dailey wrote:
> On Aug 11, 3:08 pm, Robert Dailey <rcdai...@gmail.com> wrote:
>> 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. Below is the code I am trying to
>> improve. Notice how it looks ugly/unreadable because of the way the
>> string contents are shifted all the way to the left edge of the
>> document. 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?
>>
>> Help is appreciated!
>>
>> def RunCommand( commandList ):
>> commandString =
>> print( 'Running Command:', )
>> cmd = subprocess.Popen( commandList )
>> returnCode = cmd.wait()
>> if returnCode:
>> failMsg = '''\
>> *************************************************
>> The following command returned exit code [{:#x}].
>> This represents failure of some form. Please review
>> the command output for more details on the issue.
>> ------------
>> {}
>> *************************************************
>> '''
>> commandString = ' '.join( commandList )
>> raise CommandFailure( failMsg.format( returnCode,
>> commandString ) )

>
> And yes, I recognize there are syntax errors. Ignore those for now.

For starters take a look at http://tinyurl.com/o2o8r8 , just about every
combination of string concatenation going there. I assume that one of
these will let you leave failMsg where it belongs.

--
Kindest regards.

Mark Lawrence.

 
Reply With Quote
 
Bearophile
Guest
Posts: n/a
 
      08-11-2009
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.
This may help:
http://docs.python.org/library/textw...extwrap.dedent

Bye,
bearophile
 
Reply With Quote
 
Robert Dailey
Guest
Posts: n/a
 
      08-11-2009
On Aug 11, 3:40*pm, Bearophile <bearophileH...@lycos.com> 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.
> This may help:http://docs.python.org/library/textw...extwrap.dedent
>
> Bye,
> bearophile


It's a figure of speech. And besides, why would I want programming
advice from a woman? lol. Thanks for the help.
 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      08-12-2009
Robert Dailey wrote:
> 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. Below is the code I am trying to
> improve. Notice how it looks ugly/unreadable because of the way the
> string contents are shifted all the way to the left edge of the
> document. 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?
>
> Help is appreciated!
>
> def RunCommand( commandList ):
> commandString =
> print( 'Running Command:', )
> cmd = subprocess.Popen( commandList )
> returnCode = cmd.wait()
> if returnCode:
> failMsg = '''\
> *************************************************
> The following command returned exit code [{:#x}].
> This represents failure of some form. Please review
> the command output for more details on the issue.
> ------------
> {}
> *************************************************
> '''
> commandString = ' '.join( commandList )
> raise CommandFailure( failMsg.format( returnCode,
> commandString ) )
>
>

No, don't put it in global scope. Put it externally, so it can be
readily localized for international markets.

DaveA
 
Reply With Quote
 
Simon Brunning
Guest
Posts: n/a
 
      08-12-2009
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.


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.

--
Cheers,
Simon B.
 
Reply With Quote
 
Hendrik van Rooyen
Guest
Posts: n/a
 
      08-12-2009
On Tuesday 11 August 2009 22:52:34 Robert Dailey wrote:
> On Aug 11, 3:40*pm, Bearophile <bearophileH...@lycos.com> 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.
> > This may
> > help:http://docs.python.org/library/textw...extwrap.dedent
> >
> > Bye,
> > bearophile

>
> It's a figure of speech. And besides, why would I want programming
> advice from a woman? lol. Thanks for the help.


Well it may come as a surprise to you, but it was a woman who
wrote one of the first compilers.

She became an Admiral in the US navy as a result.

If I recall correctly, her name was Grace Hooper.

How many compilers have you written from scratch,
without a compiler to help you?



- Hendrik

 
Reply With Quote
 
MRAB
Guest
Posts: n/a
 
      08-12-2009
Hendrik van Rooyen wrote:
> On Tuesday 11 August 2009 22:52:34 Robert Dailey wrote:
>> On Aug 11, 3:40 pm, Bearophile <bearophileH...@lycos.com> 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.
>>> This may
>>> help:http://docs.python.org/library/textw...extwrap.dedent
>>>
>>> Bye,
>>> bearophile

>> It's a figure of speech. And besides, why would I want programming
>> advice from a woman? lol. Thanks for the help.

>
> Well it may come as a surprise to you, but it was a woman who
> wrote one of the first compilers.
>
> She became an Admiral in the US navy as a result.
>
> If I recall correctly, her name was Grace Hooper.
>

Grace Hopper. The saying "It's easier to ask forgiveness than it is to
get permission" is attributed to her.

> How many compilers have you written from scratch,
> without a compiler to help you?
>
>
>


 
Reply With Quote
 
Robert Dailey
Guest
Posts: n/a
 
      08-12-2009
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!
 
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