Re: Converting functions

2011-01-24 Thread Peter Otten
Edmunds Cers wrote: > Peter Otten <__pete...@web.de> writes: > >> I don't know how to express it more clearly, so here's another example: >> > def f(): >> ... def g(): return a * a >> ... def h(): return a + a >> ... a = 5 >> ... return g, h >> ... > g, h = f() > g(),

Re: Converting functions

2011-01-24 Thread Edmunds Cers
Peter Otten <__pete...@web.de> writes: > I don't know how to express it more clearly, so here's another example: > def f(): > ... def g(): return a * a > ... def h(): return a + a > ... a = 5 > ... return g, h > ... g, h = f() g(), h() > (25, 10) IMHO this whole con

Re: Converting functions

2011-01-24 Thread Peter Otten
iu2 wrote: > I thought a function definition creates a closure around all used > vars. > As I understand now only variables that are passed as function > arguments can participate in a closure. No, it's just that all closures see the value of a variable at the time when the closure is run, not w

Re: Converting functions

2011-01-24 Thread iu2
On Jan 24, 9:51 am, Peter Otten <__pete...@web.de> wrote: > iu2 wrote: > > I'm trying to convert functions - pass a few functions to a converting > > function, which change their behaviour and return the changed > > functions: > > > >>> def cfuncs(*funcs): > >         n = [] > >         for f in fu

Re: Converting functions

2011-01-23 Thread Peter Otten
iu2 wrote: > I'm trying to convert functions - pass a few functions to a converting > function, which change their behaviour and return the changed > functions: > > >>> def cfuncs(*funcs): > n = [] > for f in funcs: > def ff(*args, **key): >

Converting functions

2011-01-23 Thread iu2
Hi all, I'm trying to convert functions - pass a few functions to a converting function, which change their behaviour and return the changed functions: >>> def cfuncs(*funcs): n = [] for f in funcs: def ff(*args, **key): print 'Start!', f.fu

Re: Avoid converting functions to methods in a class

2010-02-23 Thread Daniel Fetchinson
> I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): > target = mymodule.someclass > > def test_spam(self): > """Test that someclass has a spam attribute.""" > self.failUnless(h

Re: Avoid converting functions to methods in a class

2010-02-23 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: I have a convention when writing unit tests to put the target of the test into a class attribute, as follows: class MyTest(unittest.TestCase): target = mymodule.someclass def test_spam(self): """Test that someclass has a spam attribute.""" self.fa

Re: Avoid converting functions to methods in a class

2010-02-20 Thread Arnaud Delobelle
On 20 Feb, 03:33, Steven D'Aprano wrote: > I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): >     target = mymodule.someclass > >     def test_spam(self): >         """Test that someclass has a spam

Re: Avoid converting functions to methods in a class

2010-02-19 Thread Ben Finney
Steven D'Aprano writes: > I have a convention when writing unit tests Incidentally, you may be interested in the specific forum for testing in Python http://lists.idyll.org/listinfo/testing-in-python> that is a good resource for asking questions like this. > to put the target of the test into a

Re: Avoid converting functions to methods in a class

2010-02-19 Thread Chris Colbert
this is somewhat hackish: In [1]: def test(): ...: print 'spam' ...: ...: In [20]: class Ham(): : target = {'target': test} : def test_eggs(self): : self.target['target']() : : In [21]: h = Ham() In [22]: h.test_eggs() spam On Fr

Avoid converting functions to methods in a class

2010-02-19 Thread Steven D'Aprano
I have a convention when writing unit tests to put the target of the test into a class attribute, as follows: class MyTest(unittest.TestCase): target = mymodule.someclass def test_spam(self): """Test that someclass has a spam attribute.""" self.failUnless(hasattr(self.tar