>
thanks :) I'm a beginner and I was expecting this to be a member of
string so I couldnt find it anywhere in the docs.
And that's a very reasonable place to search; I think chr and ord are
builtin functions (and not str methods) just by an historical accident.
(Or is there any other reason? what's wrong with "a".ord() or
str.from_ordina l(65))?
>>>
>>So just for completion, the solution is:
>>>
>>>>>chr(ord('a ') + 1)
>>'b'
>>
>thanks :) I'm a beginner and I was expecting this to be a member of
>string so I couldnt find it anywhere in the docs.
>
And that's a very reasonable place to search; I think chr and ord are
builtin functions (and not str methods) just by an historical
accident. (Or is there any other reason? what's wrong with "a".ord()
or str.from_ordina l(65))?
Not a reason, but doesn't ord() word with unicode as well?
>>"Lutz Horn" <lutz.georg.hor n@googlemail.co mschreef in bericht
>>news:mailman. 360.1209537877. 12834.python-list@python.org ...
>>>>
>>>So just for completion, the solution is:
>>>>
>>>>>>chr(ord(' a') + 1)
>>>'b'
>>>
>>thanks :) I'm a beginner and I was expecting this to be a member of
>>string so I couldnt find it anywhere in the docs.
>>
>And that's a very reasonable place to search; I think chr and ord are
>builtin functions (and not str methods) just by an historical
>accident. (Or is there any other reason? what's wrong with "a".ord()
>or str.from_ordina l(65))?
>
>
Not a reason, but doesn't ord() word with unicode as well?
yes it does, I just read the documentation on it :)
"Gabriel Genellina" <gagsl-py2@yahoo.com.a rschreef in bericht
news:mailman.36 5.1209541507.12 834.python-list@python.org ...
En Wed, 30 Apr 2008 04:19:22 -0300, SL <ni@hao.comescr ibió:
And that's a very reasonable place to search; I think chr and ord are
builtin functions (and not str methods) just by an historical accident.
(Or is there any other reason? what's wrong with "a".ord() or
str.from_ordina l(65))?
yes when you know other OO languages you expect this. Anyone know why
builtins were chosen? Just curious
>En Wed, 30 Apr 2008 04:19:22 -0300, SL <ni@hao.comescr ibió: And
>that's a very reasonable place to search; I think chr and ord are
>builtin functions (and not str methods) just by an historical
>accident. (Or is there any other reason? what's wrong with
>"a".ord() or str.from_ordina l(65))?
>
yes when you know other OO languages you expect this. Anyone know
why builtins were chosen? Just curious
*Maybe* for aesthetical reasons. I find ord(c) more pleasent for
the eye. YMMV.
The biggest ugliness though is ",".join(). No idea why this should
be better than join(list, separator=" "). Besides, ",".join(u" x")
yields an unicode object. This is confusing (but will probably go
away with Python 3).
>>"Lutz Horn" <lutz.georg.hor n@googlemail.co mschreef in bericht
>>news:mailman. 360.1209537877. 12834.python-list@python.org ...
>>>>
>>>So just for completion, the solution is:
>>>>
>>>>>>chr(ord(' a') + 1)
>>>'b'
>>>
>>thanks :) I'm a beginner and I was expecting this to be a member of
>>string so I couldnt find it anywhere in the docs.
>>
>And that's a very reasonable place to search; I think chr and ord are
>builtin functions (and not str methods) just by an historical
>accident. (Or is there any other reason? what's wrong with "a".ord()
>or str.from_ordina l(65))?
>
>
Not a reason, but doesn't ord() word with unicode as well?
Yes, so ord() could be an instance method of both str and unicode, like
upper(), strip(), and all of them...
And str.from_ordina l(n)==chr(n), unicode.from_or dinal(n)==unich r(n)
The biggest ugliness though is ",".join(). No idea why this should
be better than join(list, separator=" "). Besides, ",".join(u" x")
yields an unicode object. This is confusing (but will probably go
away with Python 3).
It is only ugly because you aren't used to seeing method calls on string
literals. Here are some arguably less-ugly alternatives:
print str.join(", ", sequence)
or:
comma_separated = ", ".join
will let you use:
print comma_separated (sequence)
or even just:
SEPARATOR = ", "
followed by:
SEPARATOR.join( sequence)
is no more ugly than any other method call.
It would make perfect sense for join to be a method on stringlike objects
if it simply returned an object of the same type as the object it is called
on. As you point out, where it breaks down is a str separator can return a
unicode result and that is confusing: if you want a unicode result perhaps
you should be required to use a unicode separator but that isn't going to
happen (at least not in Python 2.x).
What definitely wouldn't make sense would be to make join a method of the
list type (as it is in some other languages).
>The biggest ugliness though is ",".join(). No idea why this should
>be better than join(list, separator=" "). Besides, ",".join(u" x")
>yields an unicode object. This is confusing (but will probably go
>away with Python 3).
>
It is only ugly because you aren't used to seeing method calls on
string literals.
I am used to it. Programming very much with unicode, I use .encode
and .decode very often and I like them. I consider en/decoding to
be an intrinsic feature of strings, but not ord(), which is an
"external", rather administrative operation on strings (and actually
not even this, but on characters) for my taste.
However, join() is really bizarre. The list rather than the
separator should be the leading actor.
However, join() is really bizarre. The list rather than the
separator should be the leading actor.
No, because join must work with _any sequence_, and there is no
"sequence" type to put the join method on.
This semantic certainly sets python apart from many other languages.
On Wed, 30 Apr 2008 13:12:05 +0200, Torsten Bronger wrote:
However, join() is really bizarre. The list rather than the
separator should be the leading actor.
You mean any iterable should be the leading actor, bacause `str.join()`
works with any iterable. And that's why it is implemented *once* on
string and unicode objects. Okay that's twice. :-)
Comment