Re: Accessing variable from a function within a function

2007-06-24 Thread Marcin Ciura
Nathan Harmston wrote: > Unfortunately this doesnt work since a,a1,b,b1 arent declared in the > function. Is there a way to make these variables accessible to the > euclid function. Or is there a better way to design this function? The canonical recommendations are: use attributes of the inner fun

Re: Accessing variable from a function within a function

2007-06-24 Thread James Stroud
James Stroud wrote: > Nathan Harmston wrote: > def exteuclid(m,n): > x = 0,1,1,0,m,n > def euclid(c,d,x=x): >a,a1,b,b1,c,d = x >q = c /d >r = c % d >if r == 0: >print a,b >return d >else: >print a1,a,b1,b,c,d,q,r >

Re: Accessing variable from a function within a function

2007-06-24 Thread James Stroud
Nathan Harmston wrote: > Hi, > > I m playing around with extended euclids algorithm from Knuth. I m > trying to build a function with a function inside it. > > def exteuclid(m,n): > a,a1,b,b1,c,d = 0,1,1,0,m,n > def euclid(c,d): >q = c /d >r = c % d >if r == 0: >

Re: Accessing variable from a function within a function

2007-06-24 Thread Stefan Bellon
On Sun, 24 Jun, 7stud wrote: > ef outer(): > a = 10 > def inner(): > print a > > return inner > > > f = outer() > f() > > --output:-- > 10 > >>> def outer(): ... a = 10 ... def inner(): ... a = a + 1 ... print a ... return inner ... >>> f=oute

Re: Accessing variable from a function within a function

2007-06-24 Thread 7stud
On Jun 24, 11:55 am, "Nathan Harmston" <[EMAIL PROTECTED]> wrote: > Hi, > > I m playing around with extended euclids algorithm from Knuth. I m > trying to build a function with a function inside it. > > def exteuclid(m,n): > a,a1,b,b1,c,d = 0,1,1,0,m,n > def euclid(c,d): > q = c /d >

Re: Accessing variable from a function within a function

2007-06-24 Thread Michael Hoffman
Nathan Harmston wrote: > Hi, > > I m playing around with extended euclids algorithm from Knuth. I m > trying to build a function with a function inside it. > > def exteuclid(m,n): > a,a1,b,b1,c,d = 0,1,1,0,m,n > def euclid(c,d): >q = c /d >r = c % d >if r == 0: >

Accessing variable from a function within a function

2007-06-24 Thread Nathan Harmston
Hi, I m playing around with extended euclids algorithm from Knuth. I m trying to build a function with a function inside it. def exteuclid(m,n): a,a1,b,b1,c,d = 0,1,1,0,m,n def euclid(c,d): q = c /d r = c % d if r == 0: print a,b return d