Recursive function defined within function => NameError

Ken Seehof kens at sightreader.com
Sun Feb 27 18:10:07 EST 2000


Learn OOP and stop using local functions.  :)

skaller wrote:

> Michael Ströder wrote:
> >
> > HI!
> >
> > I have a problem with a locally-defined recursive function within a
> > function. Example:
> >
> > ---------------
> > def func1():
> >
> >   def fak(n):
> >     if n>1:
> >       return n*fak(n-1)
> >     else:
> >       return n
> >
> >   print fak(6)
> >
> > func1()
> > ---------------
> >
> > But this code snippet does not work. It produces the traceback:
> []
> > Any better solution?
>
>         Sure. Use Vyper instead of Python: you code works
> right out of the box just like it should:
>
> [root at ruby] ~/links/viper/src>./vyperi t_recurse.vy
> File t_recurse.vy
> Viperi 2.0.1
> Copyright Maxtal P/L, John Skaller, Australia, 1999
> 720
> DONE: returning code 0
>
> --
> John (Max) Skaller, mailto:skaller at maxtal.com.au
> 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
> checkout Vyper http://Vyper.sourceforge.net
> download Interscript http://Interscript.sourceforge.net






More information about the Python-list mailing list