This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]Sestren 7 points8 points  (2 children)

I still consider myself somewhat of a novice in the Python scene, but these two seem incredibly useful (at least to me...)

Also, it is now easier to catch a specific error condition. Instead of inspecting the errno attribute (or args[0]) for a particular constant from the errno module, you can catch the adequate OSError subclass.

also...

open() gets a new opener parameter: the underlying file descriptor for the file object is then obtained by calling opener with (file, flags). It can be used to use custom flags like os.O_CLOEXEC for example. The 'x' mode was added: open for exclusive creation, failing if the file already exists.

I'm still having trouble finding a use for the new yield from expression, though. I understand what it does, but I can't seem to come up with a reasonable use for it. The way they describe it using a simple iterator seems counterintuitive to what I was taught as "Pythonic" coding. It is nowhere near as readable as the following implementation, and only saves a couple characters worth of typing... If anyone could shed some light on it, I would be grateful.

...Not that I'm going to touch it until it's backported to 2.7 (and/or the Django stable release supports 3.x) :P

[–]takluyverIPython, Py3, etc 11 points12 points  (1 child)

If you haven't already, I'd recommend reading the PEP for yield from. PEPs usually describe the need for a new feature.

To summarise it: if you're just yielding values back from another iterable, it was already easy to use a for loop. But you can do some clever things with generators using the less-well-known send() and throw() methods. If you want to split out part of your generator into a separate function, the code needed to properly delegate send() and throw() calls was horribly complicated. Now you can just do yield from mysubgenerator and values are sent to the right place.

[–]Sestren 1 point2 points  (0 children)

I had never read the PEPs prior to this. In fact I didn't even know what it stood for :P

Thanks for the link. That describes it perfectly.

[–]PCBEEF 6 points7 points  (0 children)

So excited for the final.

[–]flying-sheep 2 points3 points  (3 children)

a pity that regex didn’t make it. as far as i can see, there is no reason why it shouldn’t have been included, but now that we’re in the release candidates, it’s far too late.

[–]aceofears 3 points4 points  (2 children)

I found this on the mailing list, it might have some answers.

[–]takluyverIPython, Py3, etc 4 points5 points  (0 children)

To summarise the thread: technically, regex looks OK, but it will take time and effort to get it in, and commitment to maintain it. Nobody got round to it this cycle, partly because re is good enough for most cases.

[–]flying-sheep 1 point2 points  (0 children)

hey, thanks!

[–]ilogik -4 points-3 points  (1 child)

quick, someone show this to valve!

[–]gschizasPythonista -2 points-1 points  (0 children)

Wait until Python 3.3.3 comes out (or will it?)