6 ms·
An excellent article! I had wanted to get back into some python recently after seeing the changes in 3.4, I had also wanted to become more familiar with LLVM, a
by walkamages 12y ago
An excellent article! I had wanted to get back into some python recently after seeing the changes in 3.4, I had also wanted to become more familiar with LLVM, and this does both.
- gtirloni 12y agothere is this discussion (flame war?) about python3 not bringing too many benefits. i haven't made my mind yet. could you elaborate what you saw in 3.4 that was nice?
- gamesbrainiac 12y agoI'd like to know too. Are there any LLVM specific enhancements that python 3.4 brings to the table?
- exDM69 12y agoNo. AFAIK, there's nothing related to LLVM in core Python. And not in 3.4 changes either.
- exDM69 12y agoSimply put: it's a better language. The whole "discussion" is whether it makes sense to migrate since many parts of the ecosystem (many important libraries and frameworks) have not made the transition. And many distros ship Python 2 by default, Python 3 is optional. Python 3 only is not feasible. To me, the killer feature is better lazy evaluation (generators). In particular, important builtins like map, filter, zip, enumerate, etc are generators, instead of returning lists. This makes it feasible to write things like (process(line) for line in map(str.upper, open('giantfile.txt')) if line.lstrip()[0] != '#') Some of the above can also be done with itertools package in Python 2, but not everything. Python 3.4 changelog is here, it contains e.g. asynchronous io facilities (asyncio module): https://www.python.org/downloads/release/python-342/ https://www.python.org/downloads/release/python-342/ edit: added enumerate() in the example above, for line in open(filename) returns a generator in Python 2.x too. edit2: enumerate is lazy in python2, I replaced it with map(str.upper)
- halflings 12y agoThe example you gave works perfectly in Python 2.7 (would also be a generator, and you're not using map filter or else); but I agree: those should've been generators from day 1, especially zip and enumerate since they make more elegant code but often come with a performance overhead in Python 2.7
- exDM69 12y agoAh, you're absolutely right. for line in open(filename) returns a generator. I added map(str.upper, xxx) there to make it more it make sense. But the point should be obvious, without generators that would potentially consume a lot of memory.
- danohuiginn 12y agoTurning them into generators would have broken a lot of existing code, though, so it's reasonable to leave them until a major version change. Rather, these are the kind of small, obviously-useful changes that should have come immediately in 3.0, giving people some encouragement to switch.
- exDM69 12y agoMost of the breaking changes (including making map, zip, filter, etc lazy) were done in Python 3.0.
- maxerickson 12y agoPython 2 enumerate returns an 'enumerate' object that is more or less a light weight wrapper of the sequence that was passed in. Generators provide a convenient syntax to implement that sort of object.
- exDM69 12y agoD'oh. I put in a map(), that returns a list.
- danohuiginn 12y ago
- mkesper 12y agoSaner handling of Unicode, for example.
- chc 12y agoThis alone is pretty wonderful. I've only been working in Python a few months and the number of issues I've had to debug in 2.7 that came down to Unicode handling is kind of nuts.
- baq 12y agomuch better exceptions and sane unicode are the biggest improvements.
- ak217 12y agoWithout listing any of the modules or improvements that are in the standard library in 3 but backported as PyPI modules to 2 (of which there are many), here are the features that I actually use in Python 3: unicode handling that isn't insane, function annotations, async improvements, exception chaining, enums, single-dispatch generics, better SSL support, generator delegation, better int-bytes conversion support, unittest module improvements. The key point is that 2.7 is a language frozen in time, while 3.4+ is continuing to develop and improve. And most of the hand-wringing was before the critical mass of third-party modules was ported to 3.x. https://docs.python.org/3/whatsnew/3.4.html https://docs.python.org/3/whatsnew/3.4.html https://docs.python.org/3/whatsnew/3.3.html https://docs.python.org/3/whatsnew/3.3.html https://docs.python.org/3/whatsnew/3.2.html https://docs.python.org/3/whatsnew/3.2.html https://docs.python.org/3/whatsnew/3.1.html https://docs.python.org/3/whatsnew/3.1.html https://docs.python.org/3/whatsnew/3.0.html https://docs.python.org/3/whatsnew/3.0.html
- ngoldbaum 12y agoMy favorite new feature is PEP-442 [0]. Basically, it's now safe to add a __del__ method to a class without worrying about memory leaks caused by reference cycles. [0] https://www.python.org/dev/peps/pep-0442/ https://www.python.org/dev/peps/pep-0442/
- pekk 12y agoMost people should not be writing __del__ methods at all, especially if what they are trying to do is deterministic cleanup.
- bkeroack 12y agoAdd to the list: - function annotations (allows runtime type checking via third party modules) - asyncio (not as easy to use as Go's goroutines but still vastly superior to the multiprocessing module)
- andreasvc 12y agoI can't say I disagree with such sentiments, but over time I've ran into a few issues (features and performance improvements) which where only addressed in Python 3. This is reason enough to try working with Python 3.