[Tutor] when is a generator "smart?"

Jim Mooney cybervigilante at gmail.com
Sun Jun 2 18:56:50 CEST 2013


On 2 June 2013 03:39, Dave Angel <davea at davea.name> wrote:
> On 06/01/2013 11:58 PM, Jim Mooney wrote:

> I'm astounded nobody has asked you what version of Python this is for. in
> Python 2.x, the range(x,y) function produces the whole list, and then the
> expression around it converts that to a generator.  That alone would make it
> waste tons of memory (and time) for large y.
>
> So I'll ASSUME you're using 3.x, or that you actually are using xrange
> below.

Using Python 2.7 on Windows 7

Good point - subtle difference.  I'll have to make that more clear
with an autohotkey keyboard macro since I started with 3.3, discovered
a lot of stuff is still only for 2.7, and so went back to 2.7, which
I'm now using. I still sometimes type input instead of that annoying
raw_input and get a weird error. It's a bit confusing since, as a
learner, some things have been backported, so there is no simple
demarcation and there's already a lot to remember, let alone
differences. I'll be glad when this all settles out, but Py 3 has been
out awhile and an awful lot seems to only be for 2.7

Thanks to everyone for the useful tips on generators and
PyDifferences. They all go into Clipmate ;')

Jim


More information about the Tutor mailing list