Re: Python strings and coding conventions

2009-01-11 Thread John Machin
On Jan 12, 8:23 am, Mensanator  wrote:
> On Jan 11, 2:37 pm, John Machin  wrote:
>
>
>
>
>
> > On Jan 12, 5:34 am, Mensanator  wrote:
>
> > > On Jan 11, 12:12 pm, Roy Smith  wrote:
>
> > > > In article
> > > > <5db6181f-d6f6-4bdc-88c8-e12ad228c...@r41g2000prr.googlegroups.com>,
>
> > > > Mensanator  wrote:
> > > > > > What are all those line continuation characters ('\') for? ?You are 
> > > > > > aware
> > > > > > that they are unnecessary here?
>
> > > > > Actually, I wasn't aware of that. A quick review shows
> > > > > why. In the old manuals, implicit line continuation
> > > > > was in a seperate chapter (2.1.6) from implicit (2.1.5)
> > > > > so if you didn't read past 2.1.5 you would have missed it.
>
> > > > My philosophy about line continuation is to assume lines can be 
> > > > continued
> > > > after just about any piece of punctuation. If I'm wrong, the computer 
> > > > will
> > > > tell me, and then I make the computer happy by adding a \. It's easier
> > > > than looking it up, and way easier than memorizing the details.
>
> > > I proably got mine from Visual Basic where there are no
> > > exceptions to explicit line continuation marks. A least
> > > adding them when not necessary doesn't cause a problem.
>
> > Fugly code is not a problem?
>
> Is that how you justify breaing "explicit is
> better than implicit"?

I don't '''justify breaing "explicit is better than implicit"''' and
wasn't attempting to do so.

The Zen is more than one saying. No one saying trumps all others. Some
may appear to be in conflict with others. One must consider the
combined effect. Other sayings relevant to your problem are:

Beautiful is better than ugly.
Simple is better than complex.
Readability counts.

HTH,
John
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-11 Thread Mensanator
On Jan 11, 2:37�pm, John Machin  wrote:
> On Jan 12, 5:34�am, Mensanator  wrote:
>
>
>
>
>
> > On Jan 11, 12:12 pm, Roy Smith  wrote:
>
> > > In article
> > > <5db6181f-d6f6-4bdc-88c8-e12ad228c...@r41g2000prr.googlegroups.com>,
>
> > > Mensanator  wrote:
> > > > > What are all those line continuation characters ('\') for? ?You are 
> > > > > aware
> > > > > that they are unnecessary here?
>
> > > > Actually, I wasn't aware of that. A quick review shows
> > > > why. In the old manuals, implicit line continuation
> > > > was in a seperate chapter (2.1.6) from implicit (2.1.5)
> > > > so if you didn't read past 2.1.5 you would have missed it.
>
> > > My philosophy about line continuation is to assume lines can be continued
> > > after just about any piece of punctuation. If I'm wrong, the computer will
> > > tell me, and then I make the computer happy by adding a \. It's easier
> > > than looking it up, and way easier than memorizing the details.
>
> > I proably got mine from Visual Basic where there are no
> > exceptions to explicit line continuation marks. A least
> > adding them when not necessary doesn't cause a problem.
>
> Fugly code is not a problem?

Is that how you justify breaing "explicit is
better than implicit"?


--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-11 Thread John Machin
On Jan 12, 5:34 am, Mensanator  wrote:
> On Jan 11, 12:12 pm, Roy Smith  wrote:
>
>
>
>
>
> > In article
> > <5db6181f-d6f6-4bdc-88c8-e12ad228c...@r41g2000prr.googlegroups.com>,
>
> > Mensanator  wrote:
> > > > What are all those line continuation characters ('\') for? ?You are 
> > > > aware
> > > > that they are unnecessary here?
>
> > > Actually, I wasn't aware of that. A quick review shows
> > > why. In the old manuals, implicit line continuation
> > > was in a seperate chapter (2.1.6) from implicit (2.1.5)
> > > so if you didn't read past 2.1.5 you would have missed it.
>
> > My philosophy about line continuation is to assume lines can be continued
> > after just about any piece of punctuation. If I'm wrong, the computer will
> > tell me, and then I make the computer happy by adding a \. It's easier
> > than looking it up, and way easier than memorizing the details.
>
> I proably got mine from Visual Basic where there are no
> exceptions to explicit line continuation marks. A least
> adding them when not necessary doesn't cause a problem.

Fugly code is not a problem?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-11 Thread Mensanator
On Jan 11, 12:12�pm, Roy Smith  wrote:
> In article
> <5db6181f-d6f6-4bdc-88c8-e12ad228c...@r41g2000prr.googlegroups.com>,
>
> �Mensanator  wrote:
> > > What are all those line continuation characters ('\') for? ?You are aware
> > > that they are unnecessary here?
>
> > Actually, I wasn't aware of that. A quick review shows
> > why. In the old manuals, implicit line continuation
> > was in a seperate chapter (2.1.6) from implicit (2.1.5)
> > so if you didn't read past 2.1.5 you would have missed it.
>
> My philosophy about line continuation is to assume lines can be continued
> after just about any piece of punctuation. �If I'm wrong, the computer will
> tell me, and then I make the computer happy by adding a \. �It's easier
> than looking it up, and way easier than memorizing the details.

I proably got mine from Visual Basic where there are no
exceptions to explicit line continuation marks. A least
adding them when not necessary doesn't cause a problem.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-11 Thread Roy Smith
In article 
<5db6181f-d6f6-4bdc-88c8-e12ad228c...@r41g2000prr.googlegroups.com>,
 Mensanator  wrote:

> > What are all those line continuation characters ('\') for? ?You are aware
> > that they are unnecessary here?
> 
> Actually, I wasn't aware of that. A quick review shows
> why. In the old manuals, implicit line continuation
> was in a seperate chapter (2.1.6) from implicit (2.1.5)
> so if you didn't read past 2.1.5 you would have missed it.

My philosophy about line continuation is to assume lines can be continued 
after just about any piece of punctuation.  If I'm wrong, the computer will 
tell me, and then I make the computer happy by adding a \.  It's easier 
than looking it up, and way easier than memorizing the details.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-11 Thread Mensanator
On Jan 11, 3:56�am, Marc 'BlackJack' Rintsch  wrote:
> On Sat, 10 Jan 2009 20:48:21 -0800, Mensanator wrote:
> > Damn! I didn't know you could do that! And if I saw it in a program
> > listing, such would never occur to me. I was going to suggest the stupid
> > way:
>
>  ga = ['four score and seven years ago ', \
> > � � � � � 'our fathers brought forth ', \
> > � � � � � 'on this continent a new nation ', \
> > � � � � � 'conceived in liberty and dedicated ', \
> > � � � � � 'to the proposition that all men ', \
> > � � � � � 'are created equal']
>
> What are all those line continuation characters ('\') for? �You are aware
> that they are unnecessary here?

Actually, I wasn't aware of that. A quick review shows
why. In the old manuals, implicit line continuation
was in a seperate chapter (2.1.6) from implicit (2.1.5)
so if you didn't read past 2.1.5 you would have missed it.

The 2.6 manual is much better in this regard as it is
now difficult to miss.

Thanks for pointing that out as lists are just about
the only place I use line continuation.

>
> Ciao,
> � � � � Marc 'BlackJack' Rintsch

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-11 Thread MRAB

koranth...@gmail.com wrote:

On Jan 11, 9:26 am, Robert Kern  wrote:

koranth...@gmail.com wrote:

Hi,
   Python Coding Convention (PEP 8) suggests :
  Maximum Line Length
Limit all lines to a maximum of 79 characters.
  I have a string which is ~110 char long. It is a string which I am
going to print in a text file as a single string.
  i.e. in that text file, each line is taken as a different record -
so it has to be in a single line.
  Now, how can I write this code - while following PEP 8?
  I tried blockstrings, but as shown in the example below:

s = r'''

... abcd
... efgh
... '''

s

'\nabcd\nefgh\n'
   it has "\n" inserted - which will disallow printing it to a single
line.
   I thought about other options like concatenating strings etc, but
it seems very kludgy - esp since the whole string has a single meaning
and cannot be easily split to many logically. Then I thought of
creating a blockstring and then removing "\n", but it seemed
kludgier...

I usually use implicit concatenation:

s = ('some long text that '
  'needs to be split')

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco


This is a very good method.
I found another method too - on further investigation

s = "abc\

... efg"

s

'abcefg'
Only problem being that it doesnt support indentation.
So, implicit concatenation it is...


Another possibility is continuation _plus_ implicit concatenation.

def example():
message = "now is the time " \
  "for all good people ..."
print message
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-11 Thread Steve Holden
Mensanator wrote:
> On Jan 10, 10:26�pm, Robert Kern  wrote:
>> koranth...@gmail.com wrote:
>>> Hi,
>>> � �Python Coding Convention (PEP 8) suggests :
>>> � Maximum Line Length
>>> � � Limit all lines to a maximum of 79 characters.
>>> � I have a string which is ~110 char long. It is a string which I am
>>> going to print in a text file as a single string.
>>> � i.e. in that text file, each line is taken as a different record -
>>> so it has to be in a single line.
>>> � Now, how can I write this code - while following PEP 8?
>>> � I tried blockstrings, but as shown in the example below:
>> s = r'''
>>> ... abcd
>>> ... efgh
>>> ... '''
>> s
>>> '\nabcd\nefgh\n'
>>> � �it has "\n" inserted - which will disallow printing it to a single
>>> line.
>>> � �I thought about other options like concatenating strings etc, but
>>> it seems very kludgy - esp since the whole string has a single meaning
>>> and cannot be easily split to many logically. Then I thought of
>>> creating a blockstring and then removing "\n", but it seemed
>>> kludgier...
>> I usually use implicit concatenation:
>>
>> s = ('some long text that '
>> � � � 'needs to be split')
> 
> Damn! I didn't know you could do that! And if I
> saw it in a program listing, such would never occur
> to me. I was going to suggest the stupid way:
> 
Another option is escaping the newlines in triple-quoted strings:

>>> s = """Some long text that \
... needs to be split"""
>>> s
'Some long text that needs to be split'
>>>

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-11 Thread Ben Finney
Robert Kern  writes:

> I usually use implicit concatenation:
> 
> s = ('some long text that '
>  'needs to be split')

I do something very similar:

fleebnorg.spam = (
'some long text that'
' needs to be split')

The differences are:

I prefer to have indents as 4 spaces no matter how long the preceding
line is; but I also want the opening quote for the start of the string
to line up with subsequent open quotes for that string.

So I have all the portions of the string line up at the same (new)
indent level. To make that simpler without thinking about it every
time I change the first line, I simply break after the opening
parenthesis.

I prefer the continued portions to have the connecting space (or
whatever characters are contextually “connecting” in the text); this
is a greater visual cue that the string doesn't stand alone.

-- 
 \ “I went camping and borrowed a circus tent by mistake. I didn't |
  `\  notice until I got it set up. People complained because they |
_o__)   couldn't see the lake.” —Steven Wright |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-11 Thread Marc 'BlackJack' Rintsch
On Sat, 10 Jan 2009 20:48:21 -0800, Mensanator wrote:

> Damn! I didn't know you could do that! And if I saw it in a program
> listing, such would never occur to me. I was going to suggest the stupid
> way:
> 
 ga = ['four score and seven years ago ', \
>   'our fathers brought forth ', \
>   'on this continent a new nation ', \
>   'conceived in liberty and dedicated ', \
>   'to the proposition that all men ', \
>   'are created equal']

What are all those line continuation characters ('\') for?  You are aware 
that they are unnecessary here?

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-10 Thread koranthala
On Jan 11, 9:26 am, Robert Kern  wrote:
> koranth...@gmail.com wrote:
> > Hi,
> >    Python Coding Convention (PEP 8) suggests :
> >   Maximum Line Length
>
> >     Limit all lines to a maximum of 79 characters.
>
> >   I have a string which is ~110 char long. It is a string which I am
> > going to print in a text file as a single string.
> >   i.e. in that text file, each line is taken as a different record -
> > so it has to be in a single line.
>
> >   Now, how can I write this code - while following PEP 8?
> >   I tried blockstrings, but as shown in the example below:
>  s = r'''
> > ... abcd
> > ... efgh
> > ... '''
>  s
> > '\nabcd\nefgh\n'
> >    it has "\n" inserted - which will disallow printing it to a single
> > line.
>
> >    I thought about other options like concatenating strings etc, but
> > it seems very kludgy - esp since the whole string has a single meaning
> > and cannot be easily split to many logically. Then I thought of
> > creating a blockstring and then removing "\n", but it seemed
> > kludgier...
>
> I usually use implicit concatenation:
>
> s = ('some long text that '
>       'needs to be split')
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>   that is made terrible by our own mad attempt to interpret it as though it 
> had
>   an underlying truth."
>    -- Umberto Eco

This is a very good method.
I found another method too - on further investigation
>>> s = "abc\
... efg"
>>> s
'abcefg'
Only problem being that it doesnt support indentation.
So, implicit concatenation it is...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-10 Thread Mensanator
On Jan 10, 10:26�pm, Robert Kern  wrote:
> koranth...@gmail.com wrote:
> > Hi,
> > � �Python Coding Convention (PEP 8) suggests :
> > � Maximum Line Length
>
> > � � Limit all lines to a maximum of 79 characters.
>
> > � I have a string which is ~110 char long. It is a string which I am
> > going to print in a text file as a single string.
> > � i.e. in that text file, each line is taken as a different record -
> > so it has to be in a single line.
>
> > � Now, how can I write this code - while following PEP 8?
> > � I tried blockstrings, but as shown in the example below:
>  s = r'''
> > ... abcd
> > ... efgh
> > ... '''
>  s
> > '\nabcd\nefgh\n'
> > � �it has "\n" inserted - which will disallow printing it to a single
> > line.
>
> > � �I thought about other options like concatenating strings etc, but
> > it seems very kludgy - esp since the whole string has a single meaning
> > and cannot be easily split to many logically. Then I thought of
> > creating a blockstring and then removing "\n", but it seemed
> > kludgier...
>
> I usually use implicit concatenation:
>
> s = ('some long text that '
> � � � 'needs to be split')

Damn! I didn't know you could do that! And if I
saw it in a program listing, such would never occur
to me. I was going to suggest the stupid way:

>>> ga = ['four score and seven years ago ', \
  'our fathers brought forth ', \
  'on this continent a new nation ', \
  'conceived in liberty and dedicated ', \
  'to the proposition that all men ', \
  'are created equal']
>>> ''.join(ga)
'four score and seven years ago our fathers brought forth on this
continent a new nation conceived in liberty and dedicated to the
proposition that all men are created equal'


>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
> � that is made terrible by our own mad attempt to interpret it as though it 
> had
> � an underlying truth."
> � �-- Umberto Eco- Hide quoted text -
>
> - Show quoted text -

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python strings and coding conventions

2009-01-10 Thread Robert Kern

koranth...@gmail.com wrote:

Hi,
   Python Coding Convention (PEP 8) suggests :
  Maximum Line Length

Limit all lines to a maximum of 79 characters.

  I have a string which is ~110 char long. It is a string which I am
going to print in a text file as a single string.
  i.e. in that text file, each line is taken as a different record -
so it has to be in a single line.

  Now, how can I write this code - while following PEP 8?
  I tried blockstrings, but as shown in the example below:

s = r'''

... abcd
... efgh
... '''

s

'\nabcd\nefgh\n'
   it has "\n" inserted - which will disallow printing it to a single
line.

   I thought about other options like concatenating strings etc, but
it seems very kludgy - esp since the whole string has a single meaning
and cannot be easily split to many logically. Then I thought of
creating a blockstring and then removing "\n", but it seemed
kludgier...


I usually use implicit concatenation:

s = ('some long text that '
 'needs to be split')

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list