Grouping code by indentation - feature or ******?

Javier Bezos no.spam at see.below.es
Mon Mar 28 20:05:52 CEST 2005


"Dennis Lee Bieber" <wlfraed at .com> escribió en el mensaje
news:i22e41l1eo3n04mq2lp85j2mnfkdk6qrim at 4ax.com...

> > I don't think l[:5] + l[5:] = l is a handy property
> > and to me is clearly counterintuitive. Further,
[snipped in the reply]

Please, don't remove parts of my post which are
relevant to the discussion. I said:

>Further,
>I don't understand why l[a:b] has a behaviour which
>does't depend on its own logic but on that of certain
>constructs containing slices but which aren't the
>slices themselves.

You give a counterexample:

> st = "This i a string with typo, for example"
> pos = st.find("i ") + 1 # "+ 1" to get the space after "i"
> new_st = st[:pos] + "s" + st[pos:]

but that shows clearly what I was saying --
this tricky syntax means that you have not
to write st[:pos-1] in this particular code
(but you still have to "write" it in your
mind since it forms part of the logic of the
problem). These kind of hacks look perlish
to me.

Of course, the danger of being off-by-one would
be still present, but I would like to note that
if you change the syntax to avoid it in some
expressions you will find problems in another
expressions where otherwise it wouldn't be
present (counting from the end with negatives
values is particularly funny). The same applies
if the first element is 1 instead of 0, for
example.

Then, why not to leave that to the logic of
the problem and not to tricky syntaxes? A pity,
given that Python has a quite straighforward
syntax.

Javier






More information about the Python-list mailing list