[Python-ideas] .from and .to instead of .encode and .decode
Luciano Ramalho
luciano at ramalho.org
Wed Mar 18 12:24:24 CET 2015
On Wed, Mar 18, 2015 at 2:54 AM, anatoly techtonik <techtonik at gmail.com> wrote:
>> My mnemonics are "decode from cryptic bytes to human text" and "encode
>> from human text to cryptic bytes".
>
> Maybe I am thinking too low level, but there is no such thing as "human text" in
> computer memory. But I agree that using the words like "abstraction" is not a
> good idea, because Python is used by children of age 7, and things should be
> simpler.
It's a didactic mnemonic ;-).
Although str objects hold codepoints, they *are* used to represent
human text. On the other hand, we convert str to bytes when we need to
talk to the machine: writing to disk, sending over the network...
>
>> A more objective problem is: "from" is a keyword, so it can't be a method name.
>
> I don't see why "from" can not be used as a method name in Python. It can not
> be used as function name, because it will override the keyword, but method
> names are always namespaced with self. or class prefixes.
You can't write it's definition, "def from..." and you can't even
write "x.from" without a SyntaxError (instead of NameError or
AttributeError). Try it in the Python console.
The parser would need to be changed.
Best,
Luciano
--
Luciano Ramalho
| Author of Fluent Python (O'Reilly, 2015)
| http://shop.oreilly.com/product/0636920032519.do
| Professor em: http://python.pro.br
| Twitter: @ramalhoorg
More information about the Python-ideas
mailing list