English Noise Page 3.Post Syndicated from Eevee original https eev.Part of my Python FAQ, which is doomed to never be finished.Screen-Shot-2017-01-24-at-5.41.03-PM.png' alt='Di Keygen Error Has Occurred While Patching Compound' title='Di Keygen Error Has Occurred While Patching Compound' />The short answer is because its the actively developed version of the language, and you should use it for the same reason youd use 2.If youre here, Im guessing thats not enough.You need something to sweeten the deal.Well, friend, I have got a whole mess of sugar cubes just for you.And once youre convinced, you may enjoy the companion article, how to port to Python 3 It also has some more details on the diffences between Python 2 and 3, whereas this article doesnt focus too much on the features removed in Python 3.If you arent neck deep in Python, you might be wondering what the fuss is all about, or why people keep telling you that Python 3 will set your computer on fire.It wont. Python 2 is a good language, but it comes with some considerable baggage.It has two integer types it may or may not be built in a way that completely mangles 1.Unicode space it has a confusing mix of lazy and eager functional tools it has a standard library that takes batteries included to lengths beyond your wildest imagination it boasts strong typing, then casually insists that None lt 3 lt 2 overall, its just full of little dark corners containing weird throwbacks to the days of Python 1.If youre really interested, Nick Coghlan has written an exhaustive treatment of the slightly different question of why Python 3 was created.G7nz1mGOn0/hqdefault.jpg' alt='Di Keygen Error Has Occurred While Patching Compound' title='Di Keygen Error Has Occurred While Patching Compound' />This post is about why Python 3 is great, so lets focus on that.Fixing these things could break existing code, whereas virtually all code written for 2.So Python decided to fix them all at once, producing a not quite compatible new version of the language, Python 3.Nothing like this has really happened with a mainstream programming language before, and its been a bit of a bumpy ride since then.Python 3 was seemingly designed with the assumption that everyone would just port to Python 3, drop Python 2, and that would be that.Instead, its turned out that most libraries want to continue to run on both Python 2 and Python 3, which was considerably difficult to make work at first.Python 2. 5 was still in common use at the time, too, and it had none of the helpful backports that showed up in Python 2.Python 3. 0 didnt support u strings.Writing code that works on both 2.The porting effort also had a dependency problem if your library or app depends on library A, which depends on library B, which depends on C, which depends on D then none of those projects can even think about porting until Ds porting effort is finished.Early days were very slow going.Now, though, things are looking brighter.Most popular libraries work with Python 3, and those that dont are working on it.Python 3s Unicode handling, one of its most contentious changes, has had many of its wrinkles ironed out.Python 2. 7 consists largely of backported Python 3 features, making it much simpler to target 2 and 3 with the same code and both 2.Dont get me wrong, Python 2 will still be around for a while.A lot of large applications have been written for Python 2 think websites like Yelp, You.VP11-701-install-error.jpg' alt='Di Keygen Error Has Occurred While Patching Compound' title='Di Keygen Error Has Occurred While Patching Compound' />Tube, Reddit, Dropbox and porting them will take some considerable effort.I happen to know that at least one of those websites was still running 2.But if youre just getting started in Python, or looking to start a new project, there arent many reasons not to use Python 3.There are still some, yes but unless you have one specifically in mind, they probably wont affect you.I keep having Python beginners tell me that all they know about Python 3 is that some tutorial tried to ward them away from it for vague reasons.Which is ridiculous, since especially for beginners, Python 2 and 3 are fundamentally not that different.Even the python IRC channel has a few people who react, ah, somewhat passive aggressively towards mentions of Python 3.Most of the technical hurdles have long since been cleared it seems like one of the biggest roadblocks now standing in the way of Python 3 adoption is the communitys desire to sabotage itself.I think thats a huge shame.Not many people seem to want to stand up for Python 3, either.Links web browser Links is an open source text and graphic web browser with a pulldown menu system.It renders complex pages, has partial HTML4.Well, here I am, standing up for Python 3.I write all my new code in Python 3 now because Python 3 is great and you should use it.Heres why. None of this is going to blow your mind.Its just a programming language.I mean, the biggest change to Python 2 in the last decade was probably the addition of the with statement, which is nice, but hardly an earth shattering innovation.The biggest changes in Python 3 are in the same vein they should smooth out some points of confusion, help avoid common mistakes, and maybe give you a new toy to play with.Also, if youre writing a library that needs to stay compatible with Python 2, you wont actually be able to use any of this stuff.Sorry. In that case, the best reason to port is so application authors can use this stuff, rather than citing your library as the reason theyre trapped on Python 2 forever.But hey, if youre starting a brand new library that will blow everyones socks off, do feel free to make it Python 3 exclusive.Application authors, on the other hand, can go wild.Lets get the obvious thing out of the way.In Python 2, there are two string types str is a sequence of bytes which I would argue makes it not a string, and unicode is a sequence of Unicode codepoints.A literal string in source code is a str, a bytestring.Reading from a file gives you bytestrings.Source code is assumed ASCII by default.Its an 8 bit world.If you happen to be an English speaker, its very easy to write Python 2 code that seems to work perfectly, but chokes horribly if fed anything outside of ASCII.The right thing involves carefully specifying encodings everywhere and using u for virtually all your literal strings, but thats very tedious and easily forgotten.Python 3 reshuffles this to put full Unicode support front and center. Adobe Framemaker 10 Offline Activation In Adobe . Most obviously, the str type is a real text type, similar to Python 2s unicode.Literal strings are still str, but now that makes them Unicode strings.All of the structural strings names of types, functions, modules, etc.Unicode strings. Accordingly, identifiers are allowed to contain any Unicode letter characters.Unicode characters, though theres a new ascii and corresponding Unicode completely pervades the language, for better or worse.And just for the record this is way better.It is so much better.It is incredibly better.Do you know how much non ASCII garbage I type Every single em dash in this damn post was typed by hand, and Python 2 would merrily choke on them.Source files are now assumed to be UTF 8 by default, so adding an em dash in a comment will no longer break your production website.I have seen this happen.Youre still free to specify another encoding explicitly if you want, using a magic comment.There is no attempted conversion between bytes and text, as in Python 2 ba b is a Type.Error. Some modules require you to know what youre dealing with zlib.JSON is defined in terms of Unicode codepoints.Calling str on some bytes will defer to repr, producing something like bhello.But see b and bb below.Overall its pretty obvious when youve mixed bytes with text.Oh, and two huge problem children are fixed both the csv module and urllib.If youve never tried to make those work, trust me, this is miraculous.IO does its best to make everything Unicode.On Unix, this is a little hokey, since the filesystem is explicitly bytes with no defined encoding Python will trust the various locale environment variables, which on most systems will make everything UTF 8.The default encoding of text mode file IO is derived the same way and thus usually UTF 8.If its not what you expect, run locale and see what you get.Files opened in binary mode, with a b, will still read and write bytes.Python used to come in narrow and wide builds, where narrow builds actually stored Unicode as UTF 1.On a narrow build, unichr0x.F4. A3 raises Value.Error, and the length of u is 2.Surprise Maybe your code will work on someone elses machine, or maybe it wont.Python 3. 3 eliminated narrow builds.I think those are the major points.For the most part, you should be able to write code as though encodings dont exist, and the right thing will happen more often.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |