9 ms·
All of the reasonable "2+3" features in Python have already landed, like u'' strings in Python 3.3. The really big issues, like the difference between strings
by klodolph 11y ago
All of the reasonable "2+3" features in Python have already landed, like u'' strings in Python 3.3. The really big issues, like the difference between strings and bytes objects, can't really be emulated away. This isn't like WinAmp or MetaTrader where you can just reimplement the old interface in the new application. Code that mixes strings and bytestrings freely is simply not going to interface well with Python 3 code.
There are few paths for upgrading. You haven't mentioned 2to3, but I will. I've migraded projects of the same size you mention (10s of kloc) with 2to3 and the process took days, not months. About three days with one developer, actually.
There are a number of projects which also have code bases which are compatible with both Python 2 and 3. You say that once you move, you won't care about Python 2 any more, but I that's not a good reason to reject six outright. In my experience, the code isn't really "uglified" but there are just a few minor cases here and there you need to think about.
Anyway. Small-ish projects like the one you are talking about are usually not as hard to migrate as you might think. There are some exceptions, of course.
- xapata 11y ago> There are some exceptions, of course. Those exceptions are often bugs in the logic of handling text. Python 2 allows you to sweep that under the rug.
- 21 11y agoI agree that the bytes/string problem is a tough one. But the dev team created it and dropped it into the laps of it's users. The Windows API had the same problem, it was ASCII and then they added Unicode. But instead of just forcing your app to exclusively use a single one of them (sort of like use Py2 OR Py3), they allowed you to mix and match your code, and call either the old or the new version of the API. And gradually, people stopped using the older version and started using the Unicode one. Today, new Windows APIs are strictly Unicode. Of course, the solution was ugly from their side, having 2 duplicate APIs for the same thing, but it didn't brought pain to their users and allowed them to proceed at leisure.
- kstrauser 11y agoSo, it's like Python. You can still mix and match; you just have to explicitly convert between them at the appropriate points. The main breaking change is that you can't read a stream of bytes from a byte-oriented resource (say, a network connection that by definition can only send a stream of octets) and magically treat it like text elsewhere. While that's a tempting thing to want to do, it's been an unending fountain of bugs over the years. For example, in Python 2.7: >>> a = 'this is a test ಠ_ಠ' >>> b = bytes(a) >>> b 'this is a test \xe0\xb2\xa0_\xe0\xb2\xa0' >>> type(b) <type 'str'> In Python 3.5: >>> a = 'this is a test ಠ_ಠ' >>> print(a) this is a test ಠ_ಠ >>> b = bytes(a) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: string argument without an encoding >>> b = bytes(a.encode('utf-8')) >>> b b'this is a test \xe0\xb2\xa0_\xe0\xb2\xa0' >>> type(b) <class 'bytes'> In 2.7, you encode a series of Unicode values back to... a string? This is the source of all kinds of fun as functions expecting a string as input don't have a way to tell whether it's already been encoded or if they need to do so. In 3.5, there's no ambiguity. Functions that write to files or network sockets can either receive strings and know that they have to encode the strings locally, or bytes and know that they don't have to. Right up near the top of Zen we get: >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. The Python 2-style implicit conversions were awfully convenient 15 years ago when most things were ASCII. They're absolutely painful now that we've moved past the expectation that strings are arrays of single bytes.
- BuckRogers 11y agoExcept Python2 is the POSIX standard on how to handle this and I prefer retro OSs without a bytes/string distinction. Python3 is the Windows way of handling strings so the change was pure churn. Both are valid, but Linux is "pretty popular" right? So why break everyone's code just to churn the pot. If it was good for Kernigan and Richie, good for Joe Ossanna, good for Robert Pike well it's good enough for me.
- klodolph 11y agoThere isn't a "Windows" way of handling strings. You can handle strings however you want, just make sure that you pass the right data to syscalls. Windows APIs take UTF-16 or some other code page. Linux takes bytes. OS X takes UTF-8. There is no greatest common denominator. But if you use Unicode, then at least there's a well-defined way to write the syscall wrappers on all platforms. And it's not like Python 3 is forcing you to give up bytes. You can still os.listdir(b'/some/dir') and you'll get a list of bytes objects back. It's just that that's not default, since using Unicode by default simply makes more sense on a cross-platform system.