Slashdot Mirror


Python 3.4 Released

New submitter gadfium writes: "Python 3.4 has been released. It adds new library features, bug fixes, and security improvements. It includes: at standardized implementation of enumeration types, a statistics module, improvements to object finalization, a more secure and interchangeable hash algorithm for strings and binary data, asynchronous I/O support, and an installer for the pip package manager."

20 of 196 comments (clear)

  1. Ubuntu Install? by LifesABeach · · Score: 2

    That would be nice.

    1. Re:Ubuntu Install? by wjcofkc · · Score: 3, Insightful

      If someone is looking to install Python 3.4 the day it is released, they are not an average office worker. If someone is above average enough as a user to want\need this, they may as well have the expertise that goes with it. What exactly are you expecting them to be doing with it? Fully upgrading a 2.x system to 3.x will only break things - clearly nerdy goals are at hand. Therefor nerdier instruction in required. Plus there is no other way to do it on day one of it's release.

      --
      Brought to you by Carl's Junior.
  2. and... by Anonymous Coward · · Score: 5, Insightful

    And everyone will keep using 2.6/2.7, the windows XP of python.

    1. Re:and... by gweihir · · Score: 2

      There are very few reasons to stick with the old model. Sure, it takes a bit to get used to some of the changes, but it is not that hard. And most good libraries have already moved over or are compatible with both.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    2. Re: and... by dmbasso · · Score: 4, Insightful

      There are plenty of good reasons to use Python 3, it is way more elegant and consistent. The way text and binary data is dealt with is incomparably better. I doubt that anyone who ever had done any serious coding in Python 2 escaped from the mindfuckery of mixing unicode and ascii.

      The problem for a wider acceptance continues to be the libraries... for instance, Twisted. It is good that there is an async module in the standard library now, but too bad that my code already relies heavily on Twisted.

      And about the GIL: if you are complaining about it, you most probably are not using the right language for the job.

      --
      `echo $[0x853204FA81]|tr 0-9 ionbsdeaml`@gmail.com
    3. Re: and... by spitzak · · Score: 3, Informative

      This exactly.

      If your UTF-8 string is not completely valid, Python 3 barfs in useless and unpredictable ways. This is not a problem with Python 2.x.

      Until they fix the string so that an arbitrary sequence of bytes can be put into it and pulled out *UNCHANGED* without it throwing an exception then it cannot be used for any serious work. Bonus points if this is actually efficient (ie it is done by storing the bytes with a block copy).

      Furthermore it would help if "\xNN" produced raw byte values rather than the UTF-8 encoding of "\u00NN" which I can get by typing (gasp!) "\u00NN".

    4. Re: and... by Anonymous Coward · · Score: 5, Informative

      This is why there's a bytes type.

      If what you have is not text, don't use the text type.

    5. Re: and... by Anonymous Coward · · Score: 5, Informative

      The inconsistencies are fully within Python 2. My experience is closer to full-scale horror when having to consider different encodings in Python 2, and since I am from a country that actually needs these "bells and whistles" regarding encoding for regular I/O on a regular basis, I have met these issues many times. Using chains of codecs to read and write files, having to intercept exceptions and .encode() .decode() in differing combinations to be able to avoid Python 2 "double-crashing" when reporting an exception, deep level hacking to reinitialize sys.stdout before output on certain machines, etc.

      In Python 3, it does not "just work", but that is because character encoding is never a "just works" problem, and languages that say it is fail miserably in this regard as soon as it meets real world international encodings. Python 3 defines the problem correctly, and solves it natively in the best way I can imagine, by always being aware of the problem. No more prepending the u qualifier to every single string that might or might not be output (or combined with any other string that might or might not be output). Python 3 solves it correctly, by acknowledging character encoding as something that is actually an issue, and it does not make the silly assumption that ASCII is the way of the world. This assumption has been silly for at least 40 years, but many products were developed in ASCII centric regions, or at least in regions where you seldom saw more than one encoding, and never fully addressed the problem.

      The Python 3 standard library does strings right , and should get credit for it. Instead it gets flac from programmers who do not like that it does not inherit the quirks from Python 2 that we have become accustomed to (and are still miles better than in many other languages; PHP and unicode, anyone?).

      Heck, the number one reason that I have converted as many projects as I can to Python 3 is because of the blocks of encoding centered Python 2 code I can just throw out the window, and ease future maintenance. There are still some big module holdouts, but that was a much larger problem in ~2010. Today, the ones I miss in Python 3 are e.g. WXPython (where work is ongoing in the Phoenix project) and MySQLdb (the MySQL connection alternatives for Python 3 are outright silly -- either non-functional or non-documented).

      There are several introductory programming courses I know of that focuses on Python, and they all use Python 3 by default. I am sincerely looking forward to the day when Python 3 is the natural order.

      It takes a lot of motivation to change language structures from Python 2, and those working on the drafts are certainly top-class in their fields, so if one finds any design changes weird, the first instinct should be to read up on the rationales for the decisions. I have yet to encounter a change that seems "silly" or unnecessary after reading about the process.

      Also, for the early adopters, not that Python 3.3 (och 3.4, as this article is about) is not 3.0 or 3.1. There is a lot of things that have been fixed along the way.

    6. Re: and... by jythie · · Score: 2

      this kinda highlights why a lot of people are still on Python 2.x. Python 3.x kinda comes across as a language fetish rather then something pragmatic, incompatible changes for the sake of sexyness. Elegance and consistency are great when you are waxing poetic, but are off less importance when you are interested in a language as just a tool. A lot of the library authors fall into that later category, it is a tool to get a job done and Python3 does not really prioritize pragmatism.

    7. Re: and... by mypalmike · · Score: 3, Insightful

      > Unless you're a framework author, chances are you'll have to care very little about mucking with bytes.

      Right, because none of us write code that interacts with other code or systems that use bytes.

      Like C libraries.
      Or binary files.
      Or network protocols.

      --
      There are 0x40000000 types of people: those who understand 32-bit IEEE 754 floating point, and those who don't.
    8. Re:and... by jythie · · Score: 2

      When stability and consistency are more important then having new toys to play with, the lack of new features is a big selling point.

      Adding new features to a language has always been a rather controversial idea, with many feeling that languages themselves should remain limited and stable with libraries being the place new features should be added.

    9. Re: and... by spitzak · · Score: 2

      No, all that means is that EVERYTHING has to be changed to use the bytes type.

      I mean every single library function that takes a unicode string, every use of ParseTuple that translates to a string, etc. Pretty much the entire Python library must be rewritten, or a wrapper added around every function that takes a string argument.

      Everybody saying that "it's good to catch the error earlier" obviously has ZERO experience programming. Let's see, would it be a good idea if attempting to read a text file failed if there was a spelling error? Or perhaps it might be a good idea to defer this problem until it actually makes a difference?

      This crazy belief that somehow some physically possible patterns of bytes will just magically not happen because you said they are "invalid" is inexplictable. No other system than UTF-8 seems to cause this weird brain damage, no other system is so totally unprepared for invalid storage and pretends that all storage will be valid. I cannot explain it except that it seems like exposure to ASCII where all bytes sequences are always valid has rotted people's minds so that they dismiss the problem.
       

  3. Re:And it still has the GIL by steveha · · Score: 5, Insightful

    You make it sound as if it were no big deal to remove the GIL. It has been tried, and Python got 2x slower, so that attempt was abandoned. Python 3.2 gained a different implementation of the GIL, and that fixed some problems, but other problems still occur.

    The GIL is Python's hardest problem.

    https://www.jeffknupp.com/blog/2012/03/31/pythons-hardest-problem/

    https://www.jeffknupp.com/blog/2013/06/30/pythons-hardest-problem-revisited/

    As noted in the above referenced blog, you can use Jython or IronPython to avoid the GIL; PyPy will be using Software Transactional Memory to avoid the GIL; and you can use the multiprocessing module to use multiple cores without GIL problems. You do have options other than just using CPython.

    If removing the GIL was as easy as you seem to think, it would be gone now, at least in a fork of CPython. Yet still it remains.

    --
    lf(1): it's like ls(1) but sorts filenames by extension, tersely
  4. Re:Python is the new Pascal by Anonymous Coward · · Score: 3, Insightful

    it shouldn't have been a surprise that it would spell doom for Python to fork it into two incompatible branches for a couple of "it would be nice" type features.

    No.

    The Python community, overall, approves of Python 3.x. The major breakages have to do with Unicode, but that's because Python 3.x does it right and Python 2.x didn't.

    If you don't think Unicode matters, my guess is you are an English-speaking American. Others disagree.

    There are efforts underway to port the major Python projects to support 3.x. SciPy will be the big one... Django already has support for Python 3.x.

    Perl6 never went anywhere, Python 3.x is in wide use.

  5. Religeous arguments abound by EmperorOfCanada · · Score: 4, Interesting

    I have recently started bathing in the waters of Python. What I have realized is that it is a core group within Python who are rightfully proud of their 3.x accomplishment. But they are solidly ignoring the fact that only a tiny percentage of people are using it. The reasons are quite simple people will need 8 modules for their system and 1 barely works with 3.x and the other says something like "mostly works" Well most people aren't willing to depend upon "mostly".

    Now module after module is going 3.x but the other problem is that for most people having two pythons on their machine is a pain in the ass. I know there are tools to make this less painful but I can tell you an easy way to make it painless, Don't have two versions.

    Then there is this call that you should begin new projects in 3.x; but the problem again is the two versions issue.

    What bothers me about all this is that I come from a C++ / PHP world. With C++ I have upgraded countless times over many years and had close to zero problems with my code. I don't even know which compiler XCode is even using right now. With PHP my various upgrades have broken exactly one module and I hear rumours that the next big version of PHP will break one module in my older code. But I don't care as I am replacing my PHP with Python.

    Where I am worried is that the core Python people will do something stupid like announce an end of support date for 2.7. The problem there is that it might be easier for some people to install a whole different language to sit alongside Python 2.7 and start playing with that instead of smashing their machine in the teeth and simultaneously installing 3.x.

  6. Ob by Hognoxious · · Score: 4, Funny

    Have they fixed the whitespace bug yet?

    --
    Confucius say, "Find worm in apple - bad. Find half a worm - worse."
  7. There is something called multi-process you know by Viol8 · · Score: 3, Interesting

    And python has supported it (at least on unix) virtually since it was first released.

    I've never really seen much virtue in multi threading - its useful in a limited number of cases but usually it creates more problems than it solves (compared to multi process) and is usually used by people who don't really know what they're doing. Essentially multi threading takes all the advantages of protected process virtual memory and throws them in the bin.

  8. Re:And it still has the GIL by Bill_the_Engineer · · Score: 2

    Perl clones the entire interpreter for every thread.

    Which isn't a bad thing. Perl, Python, and Ruby do not run natively within a CPU. Both Python and Ruby settled on a GIL so that the interpreter could have multiple threads of execution. Perl decided that it would be faster to just give each thread its own interpreter and they were right. You can also do cool things like detach long lived threads and whatever.

    You can still fork in Python, Perl, and Ruby and give each process its own independent address space and use IPC to share data. However with Perl threads you can share variable data (with caveats) with multiple threads with threads::shared.

    --
    These comments are my own and do not necessarily reflect the views or opinions of my employer or colleagues...
  9. Re:And it still has the GIL by jythie · · Score: 2

    well, there is a good solution.. don't run multiple threads in a single memory space. The problem with people complaining about the GIL is they are coming at it from the wrong direction. The problem is people want multiple threads all able to mess with each other's data and not bother with all that pesky IPC or locking, which yes it is quicker and easier, but causes a lot of frustrating problems that people have forgotten they do not actually need to have.

  10. Re:Reference counting and unmanaged resources by steveha · · Score: 3, Insightful

    these implementations pay a penalty for relying on the VM's tracing garbage collection, and this penalty is loss of finalizer functionality.

    And this is why it is best practice in Python to use the with statement, to make sure that things get cleaned up when you are done with them.

    In CPython you can get away with just dropping your objects on the floor, and the reference counting will clean them up for you. In other implementations, not so much.

    This works okay in CPython:

    def read_data(fname):
        f = open(fname)
        return f.read()

    In CPython, with no references to f it gets cleaned up, and the open file gets closed.

    In any version of Python, this works great:

    def read_data(fname):
        with open(fname) as f:
            return f.read()

    The with statement ensures that the open file will be closed, no matter how the function is exited (including by exception).

    And I actually prefer the with statement these days... I like how it makes the lifetime explicit for the stuff it wraps.

    Raymond Hettinger has expressed the opinion that the with statement is one of the really best ideas in Python. I think that was during his PyCon session where he listed his favorite things in Python.

    --
    lf(1): it's like ls(1) but sorts filenames by extension, tersely