Re: [Tutor] Generator next()

2013-12-30 Thread spir
On 12/29/2013 12:33 PM, Steven D'Aprano wrote: def adder_factory(n): def plus(arg): return arg + n return plus # returns the function itself If you call adder_factory(), it returns a function: py> adder_factory(10) .plus at 0xb7af6f5c> What good is this? Watch carefully:

Re: [Tutor] Generator next()

2013-12-30 Thread spir
On 12/29/2013 01:38 PM, Steven D'Aprano wrote: >In the previous timer function that I was using, it defined a timer class, >and then I had to instantiate it before I could use it, and then it saved a >list of timing results. I think in yours, it adds attributes to each >instance of a function/met

Re: [Tutor] Generator next()

2013-12-29 Thread Keith Winston
Hah,I must understand,I read it that way! > > Oops, sorry a typo crept into this. That last line ought to be > "return g(23)". Sorry for any confusion. > > > > -- > Steven > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription

Re: [Tutor] Generator next()

2013-12-29 Thread Keith Winston
This is all really quite awesome, though I'm sure it'll be a while before these are really available tools for me. I think I get(a bit more than) the basic concept. Thanks! > is a short-cut for this: > > def spam(n): > return "spam"*n > > spam = decorator(spam) > > > This may be a lot to diges

Re: [Tutor] Generator next()

2013-12-29 Thread Keith Winston
Wow Steven, this is great.I'll be brief I'm on a phone > def f(x): > print("Inside the outer function x =", x) > def g(y): # a function nested inside another function > print("Inside the inner function x =", x) > print("Inside the inner function y =", y) > return x

Re: [Tutor] Generator next()

2013-12-29 Thread Steven D'Aprano
On Sun, Dec 29, 2013 at 10:33:15PM +1100, Steven D'Aprano wrote: > def f(x): > print("Inside the outer function x =", x) > def g(y): # a function nested inside another function > print("Inside the inner function x =", x) > print("Inside the inner function y =", y) >

Re: [Tutor] Generator next()

2013-12-29 Thread Steven D'Aprano
Last one! On Sun, Dec 29, 2013 at 01:57:31AM -0500, Keith Winston wrote: > In the previous timer function that I was using, it defined a timer class, > and then I had to instantiate it before I could use it, and then it saved a > list of timing results. I think in yours, it adds attributes to eac

Re: [Tutor] Generator next()

2013-12-29 Thread Steven D'Aprano
On Sun, Dec 29, 2013 at 01:57:31AM -0500, Keith Winston wrote: > Also: in the timer function, it has a series of attribute assignments to > 0/None after the inner function definition... from the behaviour, I assume > those are applied once, the first time the timer function is called > wrapping a

Re: [Tutor] Generator next()

2013-12-29 Thread Steven D'Aprano
On Sun, Dec 29, 2013 at 01:57:31AM -0500, Keith Winston wrote: > I don't really get the inner thing, I tried to look it up, but I don't > think I found the right thing, just references to nested functions. I'd > like to understand what I'm looking at better, but can't figure out what > question to

Re: [Tutor] Generator next()

2013-12-28 Thread Keith Winston
On Sat, Dec 28, 2013 at 4:45 AM, Steven D'Aprano wrote: > That's my idea of an instrumented function :-) > > Feel free to ask for a explanation of how it works. > Hey Steve or anyone: That seems like a very clean timer function, and while I have it working I only understand it caricaturistically

Re: [Tutor] Generator next()

2013-12-28 Thread eryksun
On Sat, Dec 28, 2013 at 4:45 AM, Steven D'Aprano wrote: > Anyway, if I'm going to criticise, I ought to show what I consider > better. Here's a quick and unpolished decorator for instrumenting > functions. For simplicity, it too will be inaccurate for Windows and > really fast/small functions, but

Re: [Tutor] Generator next()

2013-12-28 Thread Steven D'Aprano
On Fri, Dec 27, 2013 at 01:14:42PM -0500, Keith Winston wrote: > I am beginning to think about decorators, generators, and the like. [...] > Here's the code, stolen without apology from here: > http://enja.org/2011/03/09/a-python-function-timing-decorator/ > > import time > > class Timing(object)

Re: [Tutor] Generator next()

2013-12-27 Thread Steven D'Aprano
On Fri, Dec 27, 2013 at 07:16:22PM +, Oscar Benjamin wrote: > The next method of iterators was renamed __next__ in Python 3. So if you > change it to self.col.__next__() it will work in Python 3. Neither of those > is really correct though. The correct method is to call the next built-in: >

Re: [Tutor] Generator next()

2013-12-27 Thread Steven D'Aprano
On Fri, Dec 27, 2013 at 01:22:03PM -0500, Keith Winston wrote: > Finally: this isn't really a Python issue I don't think, but when I cut & > paste code from the web page above (in Firefox in Linux 16 XFCE) and paste > it into the IDLE New File window, it cleans out all the white space, which > is

Re: [Tutor] Generator next()

2013-12-27 Thread Oscar Benjamin
On Dec 27, 2013 6:24 PM, "Keith Winston" wrote: > > I am beginning to think about decorators, generators, and the like. I'm starting from zero. I've read a few PEPs, and looked at some code, and maybe things are starting to sink in, though I don't really have enough framework to hang it all on. It

[Tutor] Generator next()

2013-12-27 Thread Keith Winston
I am beginning to think about decorators, generators, and the like. I'm starting from zero. I've read a few PEPs, and looked at some code, and maybe things are starting to sink in, though I don't really have enough framework to hang it all on. It'll come. Anyway, I was trying to run some timing cod

Re: [Tutor] Generator next()

2013-12-27 Thread Keith Winston
Also: it works fine (in it's original form, before I changed the print statements) in 2.7, so I'm reinforced in my thinking that it's a 3.3 issue (well, a changed syntax issue). Finally: this isn't really a Python issue I don't think, but when I cut & paste code from the web page above (in Firefo