chr / ord

Ben Finney ben+python at benfinney.id.au
Tue Nov 3 00:10:20 EST 2009


Sean McIlroy <sean_mcilroy at yahoo.com> writes:

> how do i say "chr" and "ord" in the new python?

By “the new python”, what do you mean?

* Python 2.6.4, the newest released version.
* Python 2.7, a currently in-development version.
* Python 3.1, another new release (but not the latest).
* Python 3.2, a currently in-development version.
* Something else.

> the functions below (which work in 2.6.6)

I think we'll need you to have a closer look at version numbers; there
is no Python 2.6.6.

> show what i'm trying to do.

Unfortunately, they leave us guessing as to what you what to do, and
what you expect the result to be. I prefer not to guess.

> thanks if you can help.
>
> def readbytes(filepath):
>     return [ord(x) for x in open(filepath,'rb').read()]
>
> def writebytes(numbers,filepath):
>     open(filepath,'wb').write(''.join([chr(x) for x in numbers]))

Could you please show an example of a use of these functions —
preferably a complete, minimal example that anyone can run in the
declared version of Python — and what you would expect the output to be?

-- 
 \       “Remorse: Regret that one waited so long to do it.” —Henry L. |
  `\                                                           Mencken |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list