On 2/05/20 12:00 PM, Bob van der Poel wrote:
I still think that the use of a keyword like "static" would be easiest.
def foo(arg):
static counter = 0
counter += 1
if counter ...
And in this case static just means that it's a variable only readable
inside foo() and it should maint
On 2/05/20 11:30 AM, Chris Angelico wrote:
On Sat, May 2, 2020 at 9:14 AM DL Neil via Python-list
wrote:
On 28/04/20 7:36 PM, Chris Angelico wrote:
"Best"? Not sure about that. Functions are first-class objects in
Python, so a function *is* a callable object. You don't have to create
a custom
I still think that the use of a keyword like "static" would be easiest.
def foo(arg):
static counter = 0
counter += 1
if counter ...
And in this case static just means that it's a variable only readable
inside foo() and it should maintain it's value between calls. A "global"
without t
On Sat, May 2, 2020 at 9:14 AM DL Neil via Python-list
wrote:
>
> On 28/04/20 7:36 PM, Chris Angelico wrote:
> >>> "Best"? Not sure about that. Functions are first-class objects in
> >>> Python, so a function *is* a callable object. You don't have to create
> >>> a custom class with a call method
On 28/04/20 7:36 PM, Chris Angelico wrote:
"Best"? Not sure about that. Functions are first-class objects in
Python, so a function *is* a callable object. You don't have to create
a custom class with a call method just to be able to attach attributes
to your function.
ChrisA
Using a mutable o
On 28/04/2020 06:49, jf...@ms4.hinet.net wrote:
bvdp於 2020年4月28日星期二 UTC+8上午9時46分35秒寫道:
Oh my, that is very cool! So, I can do this:
def foo(i):
if not 'bar' in foo.__dict__:
foo.bar = 5
foo.bar += i
You can have function attribute created this way if you like:
def foo
Am 28.04.20 um 09:54 schrieb ast:
funny !
So we found 4 different ways to handle a memory in a function
1- Use a function parameter with a mutable default value
2- Use a function attribute
3- Use a callable object, and store your stuff inside an object attr
4- Use a closure to emulate a stat
Le 28/04/2020 à 09:52, ast a écrit :
Le 28/04/2020 à 09:39, Antoon Pardon a écrit :
Op 27/04/20 om 18:39 schreef Bob van der Poel:
Thanks Chris!
At least my code isn't (quite!) as bad as the xkcd example :)
Guess my "concern" is using the initialized array in the function:
def myfunct(
Le 28/04/2020 à 09:39, Antoon Pardon a écrit :
Op 27/04/20 om 18:39 schreef Bob van der Poel:
Thanks Chris!
At least my code isn't (quite!) as bad as the xkcd example :)
Guess my "concern" is using the initialized array in the function:
def myfunct(a, b, c=array[0,1,2,3] )
always feels
Op 27/04/20 om 18:39 schreef Bob van der Poel:
Thanks Chris!
At least my code isn't (quite!) as bad as the xkcd example :)
Guess my "concern" is using the initialized array in the function:
def myfunct(a, b, c=array[0,1,2,3] )
always feels like an abuse.
Has anyone seriously considere
On Tue, Apr 28, 2020 at 5:26 PM ast wrote:
>
> Le 28/04/2020 à 09:13, Chris Angelico a écrit :
> > On Tue, Apr 28, 2020 at 4:56 PM ast wrote:
> >>
> >> Le 27/04/2020 à 04:46, Bob van der Poel a écrit :
>
>
> >
> > "Best"? Not sure about that. Functions are first-class objects in
> > Python, so a
Le 28/04/2020 à 09:13, Chris Angelico a écrit :
On Tue, Apr 28, 2020 at 4:56 PM ast wrote:
Le 27/04/2020 à 04:46, Bob van der Poel a écrit :
"Best"? Not sure about that. Functions are first-class objects in
Python, so a function *is* a callable object. You don't have to create
a custom cl
On Tue, Apr 28, 2020 at 4:56 PM ast wrote:
>
> Le 27/04/2020 à 04:46, Bob van der Poel a écrit :
> > Does this make as much sense as anything else? I need to track calls to a
> > function to make sure it doesn't get called to too great a depth. I had a
> > global which I inc/dec and then check in
Le 28/04/2020 à 08:51, ast a écrit :
Le 27/04/2020 à 04:46, Bob van der Poel a écrit :
Does this make as much sense as anything else? I need to track calls to a
function to make sure it doesn't get called to too great a depth. I had a
global which I inc/dec and then check in the function. Works
Le 27/04/2020 à 04:46, Bob van der Poel a écrit :
Does this make as much sense as anything else? I need to track calls to a
function to make sure it doesn't get called to too great a depth. I had a
global which I inc/dec and then check in the function. Works fine, but I do
need to keep a global a
bvdp於 2020年4月28日星期二 UTC+8上午9時46分35秒寫道:
> Oh my, that is very cool! So, I can do this:
>
> def foo(i):
> if not 'bar' in foo.__dict__:
> foo.bar = 5
> foo.bar += i
You can have function attribute created this way if you like:
def foo(i):
foo.bar += i
foo.bar = 5
-
Oh my, that is very cool! So, I can do this:
def foo(i):
if not 'bar' in foo.__dict__:
foo.bar = 5
foo.bar += i
for a in range(10):
foo(1)
print (foo.bar)
Thanks. I will have to play more with this.
On Mon, Apr 27, 2020 at 5:31 PM Michael Torrie wrote:
> On 4/27/20 1
On 4/27/20 10:39 AM, Bob van der Poel wrote:
> Thanks Chris!
>
> At least my code isn't (quite!) as bad as the xkcd example :)
>
> Guess my "concern" is using the initialized array in the function:
>
>def myfunct(a, b, c=array[0,1,2,3] )
>
> always feels like an abuse.
>
> Has anyone serio
Thanks Chris!
At least my code isn't (quite!) as bad as the xkcd example :)
Guess my "concern" is using the initialized array in the function:
def myfunct(a, b, c=array[0,1,2,3] )
always feels like an abuse.
Has anyone seriously considered implementing a true static variable in a
function?
On Mon, Apr 27, 2020 at 1:39 PM Bob van der Poel wrote:
>
> Does this make as much sense as anything else? I need to track calls to a
> function to make sure it doesn't get called to too great a depth. I had a
> global which I inc/dec and then check in the function. Works fine, but I do
> need to
Does this make as much sense as anything else? I need to track calls to a
function to make sure it doesn't get called to too great a depth. I had a
global which I inc/dec and then check in the function. Works fine, but I do
need to keep a global around just for this.
So ... instead I wrote a short
21 matches
Mail list logo