Re: Functionality like local static in C

2022-04-15 Thread Chris Angelico
On Sat, 16 Apr 2022 at 04:51, Python wrote: > > Cecil Westerhof wrote: > > In C when you declare a variable static in a function, the variable > > retains its value between function calls. > > The first time the function is called it has the default value (0 for > > an int). > > But when the

Re: Functionality like local static in C

2022-04-15 Thread Python
Cecil Westerhof wrote: In C when you declare a variable static in a function, the variable retains its value between function calls. The first time the function is called it has the default value (0 for an int). But when the function changes the value in a call (for example to 43), the next time

Re: Functionality like local static in C

2022-04-15 Thread Cecil Westerhof via Python-list
Thanks for the multiple answers. I was pleasantly surprised. I have something to think about. :-D In principle I selected a solution for the problem for which I asked it, but I first have to finish some other stuff. I hope to find time to implement it next week. Everyone a good weekend and

RE: Functionality like local static in C

2022-04-14 Thread Schachner, Joseph
Yes, python has something like that. In fact, two things. 1) Generator. Use a "yield" statement. Every call "yields" a new value. The state of the function (local variables) is remembered from each previous call to the next. 2) In a file, declare a variable to be global. In the

Re: Functionality like local static in C

2022-04-14 Thread Chris Angelico
On Fri, 15 Apr 2022 at 03:53, Sam Ezeh wrote: > > I've seen people use function attributes for this. > ``` > Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> def function(): > ...

Re: Functionality like local static in C

2022-04-14 Thread Dieter Maurer
Cecil Westerhof wrote at 2022-4-14 17:02 +0200: >In C when you declare a variable static in a function, the variable >retains its value between function calls. >The first time the function is called it has the default value (0 for >an int). >But when the function changes the value in a call (for

Re: Functionality like local static in C

2022-04-14 Thread Joe Pfeiffer
Cecil Westerhof writes: > In C when you declare a variable static in a function, the variable > retains its value between function calls. > The first time the function is called it has the default value (0 for > an int). > But when the function changes the value in a call (for example to 43), >

Re: Functionality like local static in C

2022-04-14 Thread Sam Ezeh
I've seen people use function attributes for this. ``` Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> def function(): ... print(function.variable) ... function.variable += 1 ... >>>

Re: Functionality like local static in C

2022-04-14 Thread Mirko via Python-list
Am 14.04.2022 um 17:02 schrieb Cecil Westerhof via Python-list: > In C when you declare a variable static in a function, the variable > retains its value between function calls. > The first time the function is called it has the default value (0 for > an int). > But when the function changes the

Re: Functionality like local static in C

2022-04-14 Thread Barry
> On 14 Apr 2022, at 16:28, Cecil Westerhof via Python-list > wrote: > > In C when you declare a variable static in a function, the variable > retains its value between function calls. > The first time the function is called it has the default value (0 for > an int). > But when the function