using binary in python

Chris Angelico rosuav at gmail.com
Mon Nov 9 08:52:13 EST 2015


On Tue, Nov 10, 2015 at 12:25 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> So we have this stack:
>
>   +-------------+
>   | Application |
>   +-------------+
>   |   Python    |
>   +-------------+
>   |    UNIX     |
>   +-------------+
>
> The question is, does Python want to be "just a programming language"
> that exposes UNIX to the application program? Or does Python want to
> present an abstraction different than UNIX? IOW, is the dividing line
> between the application and the operating system above or below Python?
>
> It is evident that Python3 has intentionally moved away from the "just a
> programming language" view toward Java's write-once-run-everywhere
> ideal.
>
>
> You would be correct that the original UNIX file system model was based
> on somewhat of a naive falsity, namely text=ASCII. No matter how you
> view it, there is a conflict of sorts. Python3 is trying to pave over
> the conflict, but personally I would prefer the programming language
> just give me the OS, warts and all.

Then you don't want Python. The point of Python is to give you data
types like "list", "dict", "int" (not a machine word but a bignum),
and so on. It's NOT meant to be a thin wrapper around what your OS
offers. Python's string is a Unicode string, not a series of bytes (as
is C's char* type), because human text is better represented as
Unicode than as bytes; so it stands to reason that Python's files
should be able to contain text, since it's the one most obvious
substrate for data storage other than bytes. You get two easy options
(bytes and text), and for everything else you can use a library that's
built on one of those (pickle, json, etc) or a database.

I expect to be able to write idiomatic Python code and have it run on
Windows, Unix, Mac OS, OS/2, or Mozilla Firefox, and do the same
thing. Since those platforms are so very different, supporting all
five is going to mean restricting myself to only those operations that
are common to them all, but I expect those operations to be spelled
the same way and have the same semantics. I do NOT expect that
multiplying 123456 by 654321 will return 80779853376 on some platforms
and 3470442048 on others, nor do I expect "µ" to render as a micro
sign on some systems, a box drawing character "╡" on others, and as a
capital A with acute "Á" on the rest. (Examples not chosen at random.)
Obviously this is an ideal that sometimes can't be achieved perfectly
(Windows vs Unix file system rules, for instance), but it's definitely
part of Python's goal.

If you want C, you know where to get it. Though even C does quite a
bit of papering-over, so maybe you want to be writing assembly code.

ChrisA



More information about the Python-list mailing list