Chris Jerdonek chris.jerdo...@gmail.com added the comment:
Great. Looks good!
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13857
___
___
Changes by Nick Coghlan ncogh...@gmail.com:
--
assignee: - ncoghlan
stage: needs patch - patch review
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13857
___
Roundup Robot devn...@psf.upfronthosting.co.za added the comment:
New changeset 6f7afe25d681 by Nick Coghlan in branch 'default':
Close #13857: Added textwrap.indent() function (initial patch by Ezra
http://hg.python.org/cpython/rev/6f7afe25d681
--
nosy: +python-dev
resolution: - fixed
Nick Coghlan ncogh...@gmail.com added the comment:
Ezra (and anyone interested) may want to take a look at the checked in version
to see some of the changes I made while preparing the patch for commit.
- name changes and slight restructure as discussed on the review
- splitlines() invocation
Changes by Nick Coghlan ncogh...@gmail.com:
--
resolution: - fixed
stage: patch review - committed/rejected
status: open - closed
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13857
___
Nick Coghlan ncogh...@gmail.com added the comment:
Added some review comments. I'm thinking the docs for str.splitlines() could
really do with an update to say explicitly that a trailing newline *doesn't*
append an empty string to the result.
--
R. David Murray rdmur...@bitdance.com added the comment:
Why would you expect it to?
'a\nb'.splitlines()
['a', 'b']
'a\nb\n'.splitlines()
['a', 'b']
'a\nb\n\n'.splitlines()
['a', 'b', '']
That's exactly what I would intuitively expect, and I don't see how it could
possibly do anything
Chris Jerdonek chris.jerdo...@gmail.com added the comment:
Perhaps because that's what str.split() does:
a\nb.split(\n)
['a', 'b']
a\nb\n.split(\n)
['a', 'b', '']
a\nb\n\n.split(\n)
['a', 'b', '', '']
--
___
Python tracker rep...@bugs.python.org
R. David Murray rdmur...@bitdance.com added the comment:
That's why it's a different function :) (Well, that and universal newline
support). But I can see that explaining the difference between split and
splitlines would be worthwhile.
--
___
Nick Coghlan ncogh...@gmail.com added the comment:
I created #14957 to cover improving the str.splitlines docs.
For this patch, I think Chris is right that it should be using
str.splitlines(True) and joining on '' instead of '\n' so that Windows line
endings get preserved.
--
Chris Jerdonek chris.jerdo...@gmail.com added the comment:
I'd like to see this enhancement as well. It seems that not even a TextWrapper
is capable of a simple indent (because TextWrapper methods operate on
paragraphs rather than lines).
--
nosy: +cjerdonek
Chris Jerdonek chris.jerdo...@gmail.com added the comment:
Should the function work for strings with non-Unix line endings?
http://docs.python.org/dev/py3k/reference/lexical_analysis.html#physical-lines
For example, should indent(abc\r\n, ) return the same string, and should
\r\n get indented
Changes by Michael.Elsdörfer mich...@elsdoerfer.info:
--
nosy: +elsdoerfer
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13857
___
___
Changes by Vladimir Rutsky altsy...@gmail.com:
--
nosy: +rutsky
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13857
___
___
Python-bugs-list
Georg Brandl ge...@python.org added the comment:
IMO removing trailing newlines is not acceptable. You could use
splitlines(keepends=True) to keep final newlines (but then the default function
that determines lines to indent needs to ignore these newlines).
--
Ezra Berch ezrabe...@mac.com added the comment:
Sorry, I guess I wasn't clear. The trailing-newlines issue was an issue with
the conditional expression ncoghlan suggested. It's fixed in the patch I
submitted (and covered by the tests).
--
___
Justin Wehnes jweh...@gmail.com added the comment:
Just wondering if someone is already working on this or am I free to supply a
patch?
--
nosy: +jwehnes
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13857
Nick Coghlan ncogh...@gmail.com added the comment:
Please go ahead!
And Georg is right - the short spelling doesn't handle the first line
correctly. It also suffers from the trailing whitespace problem that Amaury
pointed out in my original version.
The tests for the new function should
Ezra Berch ezrabe...@mac.com added the comment:
I've created a patch using the conditional expression in msg151945. The one
problem I found with it is that when the input string is terminated by a
newline it removes that newline.
I've added an optional third argument: a function which
Georg Brandl ge...@python.org added the comment:
BTW, the short spelling looks like it wouldn't indent the first line.
--
nosy: +georg.brandl
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13857
Georg Brandl ge...@python.org added the comment:
Otherwise +1.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13857
___
___
Python-bugs-list
Nick Coghlan ncogh...@gmail.com added the comment:
David Miller pointed out a shorter spelling:
s.replace('\n', '\n' + (4 * ' '))
Still not particularly obvious to the reader (or writer), though.
--
___
Python tracker rep...@bugs.python.org
Amaury Forgeot d'Arc amaur...@gmail.com added the comment:
If such a function is added, I'd like the option to not indent empty lines:
trailing spaces are often not a good idea.
--
nosy: +amaury.forgeotdarc
___
Python tracker rep...@bugs.python.org
Nick Coghlan ncogh...@gmail.com added the comment:
I'd actually suggest that as the default behaviour (and is a good argument in
favour of a dedicated function in textwrap - both suggested alternatives will
blithely add whitespace to otherwise empty lines).
To handle the empty line requires
Jon Brandvein jon.brandv...@gmail.com added the comment:
If such a function is added, I'd like the option to not indent empty lines:
trailing spaces are often not a good idea.
From dedent's documentation, it wasn't immediately clear to me that it ignores
blank lines when determining common
New submission from Nick Coghlan ncogh...@gmail.com:
As far I am aware, the simplest way to indent a multi-line string is with the
following snippet:
'\n'.join((4 * ' ') + x for x in s.splitlines())
It would be a lot simpler and clearer if I could just write that as
textwrap.indent(s, 4
26 matches
Mail list logo