Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43535
| Date | 2013-04-13 11:03 -0700 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: API design for Python 2 / 3 compatibility |
| References | <51698989.2070805@sschwarzer.net> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.566.1365877587.3114.python-list@python.org> (permalink) |
On 04/13/2013 09:36 AM, Stefan Schwarzer wrote: > * Approach 2 > > When opening remote text files for reading, ftputil will > always return unicode strings from `read(line/s)`, > regardless of whether it runs under Python 2 or Python 3. > > Pro: Uniform API, independent on underlying Python > version. > > Pro: Supporting a single API will result in cleaner code > in ftputil than when supporting different APIs (see > above). > > Con: This approach might break some code which expects > the returned strings under Python 2 to be byte strings. > > Con: Developers who only use Python 2 might be confused > if ftputil returns unicode strings from `read(line/s)` > since this behavior doesn't match files opened with > `open` in Python 2. > > Which approach do you recommend and why do you prefer that > approach? Approach 2, because it is much saner to deal with unicode inside the program, and only switch back to some kind of encoding when writing to files/pipes/etc. Since you are going to support python 3 as well you can bump the major version number and note the backward incompatibility. -- ~Ethan~
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
API design for Python 2 / 3 compatibility Stefan Schwarzer <sschwarzer@sschwarzer.net> - 2013-04-13 18:36 +0200 Re: API design for Python 2 / 3 compatibility Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-13 13:32 -0400 Re: API design for Python 2 / 3 compatibility Ethan Furman <ethan@stoneleaf.us> - 2013-04-13 11:03 -0700 Re: API design for Python 2 / 3 compatibility Stefan Schwarzer <sschwarzer@sschwarzer.net> - 2013-04-14 13:11 +0200
csiph-web