[EMAIL PROTECTED] wrote:
> Xah Lee <[EMAIL PROTECTED]> wrote:
>
> > is it possible in Python to create a function that maintains a
> > variable value?
>
> Yes. There's no concept of a 'static' function variable as such, but
> there are many other ways to achieve the same thing.
>
> > globe=0;
> > d
Nevermind. I was thinking too much. :) Thanks.
Xah
Peter Hansen wrote:
> Xah Lee wrote:
> >>def myFun(var):
> >> return var+1
> >>globe = 0
> >>globe = myFun(globe)
> >
> > this is intriguing. How does it work?
> > not a rhetorical question, but where in the python doc can i read
about
> > it
Xah Lee wrote:
def myFun(var):
return var+1
globe = 0
globe = myFun(globe)
this is intriguing. How does it work?
not a rhetorical question, but where in the python doc can i read about
it?
The tutorial, presumably, since there is nothing here
that isn't covered by the most basic aspects of Python
>def myFun(var):
> return var+1
>globe = 0
>globe = myFun(globe)
this is intriguing. How does it work?
not a rhetorical question, but where in the python doc can i read about
it?
thanks.
Xah
[EMAIL PROTECTED]
http://xahlee.org/PageTwo_dir/more.html
--
http://mail.python.org/mailman/listi
Reinhold Birkenfeld wrote:
> or with a default function argument:
>
>
> class Dummy: pass
>
> def myFun(globe=Dummy()):
> try:globe.globe += 1
> except: globe.globe = 1
>
> return globe.globe
A quicker way:
def myFun(globe=[0]):
globe[0] += 1
return globe[0]
Reinhold
On Sun, 06 Mar 2005 09:44:41 +0100, Patrick Useldinger
<[EMAIL PROTECTED]> wrote:
> Xah Lee wrote:
>
> > globe=0;
> > def myFun():
> > globe=globe+1
> > return globe
>
> The short answer is to use the global statement:
>
> globe=0
> def myFun():
>global globe
>globe=globe+1
>retu
"Xah Lee" <[EMAIL PROTECTED]> writes:
> the Python doc is quite stilted. Where in the python doc is a programer
> supposed read about how the package/module system in Python works?
> (besides the tutorial that touches it)
The python docs at http://docs.python.org/ref/naming.html > are
perfectly c
Patrick Useldinger wrote:
Kent Johnson wrote:
globe=0
globe=myfun(globe)
def myFun(var):
return var+1
This mystifies me. What is myfun()? What is var intended to be?
myfun is an error ;-) should be myFun, of course.
var is parameter of function myFun. If you call myFun with variable
globe, all
Kent Johnson wrote:
globe=0
globe=myfun(globe)
def myFun(var):
return var+1
This mystifies me. What is myfun()? What is var intended to be?
myfun is an error ;-) should be myFun, of course.
var is parameter of function myFun. If you call myFun with variable
globe, all references to var will be
I believe python docs are quite *un*-stilted. Modules and packages are
not complicated. Read chapter 7 of the nutshell, it's only 10 pages
long. 2.3 and 2.4 didn't introduce any fundamental changes in how
modules work AFAIK
--
http://mail.python.org/mailman/listinfo/python-list
"Xah Lee" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> globe=0;
> def myFun():
> globe=globe+1
> return globe
>
> apparently it can't be done like that. I thought it can probably be
> done by prefixing the variable with some package context...
You can do this:
globe=0
Xah Lee wrote:
> is it possible in Python to create a function that maintains a variable
> value?
>
> something like this:
>
> globe=0;
> def myFun():
> globe=globe+1
> return globe
You could work with function attributes:
def myFun():
try:myFun.globe += 1
except: myFun.globe =
and make it a singleton, viz:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52558
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531
http://www.python.org/2.2.3/descrintro.html
(scroll wayyy down)
--
http://mail.python.org/mailman/listinfo/python-list
Patrick Useldinger wrote:
The short answer is to use the global statement:
globe=0
def myFun():
global globe
globe=globe+1
return globe
more elegant is:
globe=0
globe=myfun(globe)
def myFun(var):
return var+1
This mystifies me. What is myfun()? What is var intended to be?
Kent
--
http://mai
Xah Lee <[EMAIL PROTECTED]> wrote:
> is it possible in Python to create a function that maintains a
> variable value?
Yes. There's no concept of a 'static' function variable as such, but
there are many other ways to achieve the same thing.
> globe=0;
> def myFun():
> globe=globe+1
> return g
Xah Lee wrote:
globe=0;
def myFun():
globe=globe+1
return globe
The short answer is to use the global statement:
globe=0
def myFun():
global globe
globe=globe+1
return globe
more elegant is:
globe=0
globe=myfun(globe)
def myFun(var):
return var+1
and still more elegant is using classes
16 matches
Mail list logo