On Nov 13, 4:23 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> def static(**vars):
> ns = NS(vars)
> def deco(f):
> return lambda *args, **kwargs: f(ns, *args, **kwargs)
> return deco
>
> @static(ncalls=0, history=[])
> def foo(ns, x):
> ns.ncalls += 1
> ns.history.appe
Joe Strout <[EMAIL PROTECTED]> writes:
> On Nov 13, 2008, at 3:23 PM, Arnaud Delobelle wrote:
>
>> Aaron Brady <[EMAIL PROTECTED]> writes:
>>
>>> One way around it, which I like the idea of but I'll be honest, I've
>>> never used, is getting a function a 'self' parameter. You could make
>>> it a
On Nov 13, 2008, at 8:26 PM, Steven D'Aprano wrote:
def spam(_count=[0]):
_count[0] += 1
return "spam " * _count[0]
This is a common trick, often used for things like caching. One major
advantage is that you are exposing the cache as an *optional* part
of the
interface, which make
On Nov 13, 2008, at 3:23 PM, Arnaud Delobelle wrote:
Aaron Brady <[EMAIL PROTECTED]> writes:
One way around it, which I like the idea of but I'll be honest, I've
never used, is getting a function a 'self' parameter. You could make
it a dictionary or a blank container object, or just the funct
On Thu, Nov 13, 2008 at 10:25 PM, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Fri, 14 Nov 2008 13:35:02 +1100, Ben Finney wrote:
>
>> Instead, it looks like you're falling foul of one of the classic
>> mistakes in the "How to ask questions the smart way" document: you've
>> got a goal, but you'
Matimus a écrit :
On Nov 13, 9:16 am, Joe Strout <[EMAIL PROTECTED]> wrote:
(snip)
def spam2():
if not hasattr(spam2,'count'):spam2.count=0
spam2.count += 1
return "spam2 " * spam2.count
This is definitely preferred over the first.
I beg to disagree. This solution stores
Quoting Joe Strout <[EMAIL PROTECTED]>:
> Hi Luis,
>
> > A lot of languages have ditched the "concept" of a static variable
> > on a method (how do
> > you parse that sentence, btw?) in favour of using encapsulation.
>
> A static variable IS encapsulation. Encapsulation happens at many
>
Joe Strout a écrit :
One thing I miss as I move from REALbasic to Python is the ability to
have static storage within a method
s/method/function/
-- i.e. storage that is persistent
between calls, but not visible outside the method. I frequently use
this for such things as caching, or for ke
Steven D'Aprano wrote:
> On Thu, 13 Nov 2008 19:52:13 -0700, Joe Strout wrote:
>
>> Pity there isn't a way for a function to get a reference to itself
>> except by name. Still, when you rename a method, you're going to have
>> to update all the callers anyway -- updating a couple of extra
>> ref
On Nov 13, 10:25 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Fri, 14 Nov 2008 13:35:02 +1100, Ben Finney wrote:
> > Instead, it looks like you're falling foul of one of the classic
> > mistakes in the “How to ask questions the smart way” document: you've
> > got a goal, b
On Thu, 13 Nov 2008 18:57:37 -0800, alex23 wrote:
> On Nov 14, 12:16 pm, Joe Strout <[EMAIL PROTECTED]> wrote:
>> Argh. I've been back in the Python community for about a month, and
>> I've been continually amazed at how every single "how do I do X" or
>> "what do you think of this method of doin
On Thu, 13 Nov 2008 19:52:13 -0700, Joe Strout wrote:
> Pity there isn't a way for a function to get a reference to itself
> except by name. Still, when you rename a method, you're going to have
> to update all the callers anyway -- updating a couple of extra
> references within the method is not
On Fri, 14 Nov 2008 13:35:02 +1100, Ben Finney wrote:
> Instead, it looks like you're falling foul of one of the classic
> mistakes in the “How to ask questions the smart way” document: you've
> got a goal, but you're assuming that you need to use a specific tool to
> get there. Instead, you're be
On Thu, 13 Nov 2008 14:25:08 -0800, Paul Boddie wrote:
> On 13 Nov, 18:16, Joe Strout <[EMAIL PROTECTED]> wrote:
>> One thing I miss as I move from REALbasic to Python is the ability to
>> have static storage within a method -- i.e. storage that is persistent
>> between calls, but not visible outs
Hi Luis,
A lot of languages have ditched the "concept" of a static variable
on a method (how do
you parse that sentence, btw?) in favour of using encapsulation.
A static variable IS encapsulation. Encapsulation happens at many
levels: module, class, instance, and (in languages that suppor
On Thu, 13 Nov 2008 13:35:21 -0500, Steve Holden wrote:
> Joe Strout wrote:
>> One thing I miss as I move from REALbasic to Python is the ability to
>> have static storage within a method -- i.e. storage that is persistent
>> between calls, but not visible outside the method. I frequently use
>>
On Thu, 13 Nov 2008 14:05:17 -0500, Jean-Paul Calderone wrote:
> On Thu, 13 Nov 2008 10:58:49 -0800 (PST), [EMAIL PROTECTED] wrote:
>>On Nov 13, 11:32 am, "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote:
>>> On Thu, 2008-11-13 at 09:38 -0800, Matimus wrote:
>> [snip]
>>> > Preserving state is what class
On Thu, 13 Nov 2008 10:16:59 -0700, Joe Strout wrote:
> One thing I miss as I move from REALbasic to Python is the ability to
> have static storage within a method -- i.e. storage that is persistent
> between calls, but not visible outside the method. I frequently use
> this for such things as ca
Aaron Brady <[EMAIL PROTECTED]> writes:
> One way around it, which I like the idea of but I'll be honest, I've
> never used, is getting a function a 'self' parameter. You could make
> it a dictionary or a blank container object, or just the function
> itself.
>
> @self_param
> def spam( self ):
>
On Nov 13, 9:22 pm, Joe Strout <[EMAIL PROTECTED]> wrote:
> Steve wrote:
> > This is a pretty bizarre requirement, IMHO. The normal place to keep
> > such information is either class variables or instance variables.
>
> Holy cow, I thought it was just Chris, but there were half a dozen
> similar
Quoting Joe Strout <[EMAIL PROTECTED]>:
> On Nov 13, 2008, at 10:19 AM, Chris Mellon wrote:
>
> > Static storage is a way of preserving state. Objects are a way of
> > encapsulating state and behavior. Use an object.
>
> Argh. I've been back in the Python community for about a month, and
>
On Nov 14, 12:16 pm, Joe Strout <[EMAIL PROTECTED]> wrote:
> Argh. I've been back in the Python community for about a month, and
> I've been continually amazed at how every single "how do I do X" or
> "what do you think of this method of doing X" question is answered by
> people on high hors
On Nov 13, 2008, at 11:15 AM, J. Cliff Dyer wrote:
Here are a few essays into the matter
def foo():
... foo._count += 1
... return ("spam " * foo.count).rstrip()
Simple and straightforward, and _count is still encapsulated in the
function, but it's kind of ugly, because when the func
Joe Strout <[EMAIL PROTECTED]> writes:
> On Nov 13, 2008, at 10:19 AM, Chris Mellon wrote:
>
> > Static storage is a way of preserving state. Objects are a way of
> > encapsulating state and behavior. Use an object.
>
> Argh. I've been back in the Python community for about a month, and
> I've b
Steve wrote:
This is a pretty bizarre requirement, IMHO. The normal place to keep
such information is either class variables or instance variables.
Holy cow, I thought it was just Chris, but there were half a dozen
similar responses after that.
I'm starting to see a pattern here... any tim
On Nov 13, 2008, at 10:19 AM, Chris Mellon wrote:
Static storage is a way of preserving state. Objects are a way of
encapsulating state and behavior. Use an object.
Argh. I've been back in the Python community for about a month, and
I've been continually amazed at how every single "how do I
Ben Finney wrote:
> Joe Strout <[EMAIL PROTECTED]> writes:
>
>> One thing I miss as I move from REALbasic to Python is the ability
>> to have static storage within a method -- i.e. storage that is
>> persistent between calls
>
> This is precisely what classes are for: allowing functionality and
>
Joe Strout <[EMAIL PROTECTED]> writes:
> One thing I miss as I move from REALbasic to Python is the ability
> to have static storage within a method -- i.e. storage that is
> persistent between calls
This is precisely what classes are for: allowing functionality and
state to exist in a single obj
On Nov 13, 4:13 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Nov 13, 3:08 pm, Aaron Brady <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Nov 13, 11:16 am, Joe Strout <[EMAIL PROTECTED]> wrote:
>
> > > One thing I miss as I move from REALbasic to Python is the ability to
> > > have static storage wit
On 13 Nov, 18:16, Joe Strout <[EMAIL PROTECTED]> wrote:
> One thing I miss as I move from REALbasic to Python is the ability to
> have static storage within a method -- i.e. storage that is persistent
> between calls, but not visible outside the method. I frequently use
> this for such things as c
On Nov 13, 3:08 pm, Aaron Brady <[EMAIL PROTECTED]> wrote:
> On Nov 13, 11:16 am, Joe Strout <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > One thing I miss as I move from REALbasic to Python is the ability to
> > have static storage within a method -- i.e. storage that is persistent
> > between call
On Nov 13, 11:16 am, Joe Strout <[EMAIL PROTECTED]> wrote:
> One thing I miss as I move from REALbasic to Python is the ability to
> have static storage within a method -- i.e. storage that is persistent
> between calls, but not visible outside the method. I frequently use
> this for such th
Steve Holden wrote:
> Joe Strout wrote:
>> One thing I miss as I move from REALbasic to Python is the ability to
>> have static storage within a method -- i.e. storage that is persistent
>> between calls, but not visible outside the method. I frequently use
>> this for such things as caching, or f
On Nov 13, 12:05 pm, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> On Thu, 13 Nov 2008 10:58:49 -0800 (PST), [EMAIL PROTECTED] wrote:
> >On Nov 13, 11:32 am, "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote:
> >> On Thu, 2008-11-13 at 09:38 -0800, Matimus wrote:
> > [snip]
> >> > Preserving state is wh
On Thu, 13 Nov 2008 10:58:49 -0800 (PST), [EMAIL PROTECTED] wrote:
On Nov 13, 11:32 am, "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote:
On Thu, 2008-11-13 at 09:38 -0800, Matimus wrote:
[snip]
> Preserving state is what classes are for.
Preserving state is what *objects* are for.
Not exclusively
On Nov 13, 11:32 am, "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote:
> On Thu, 2008-11-13 at 09:38 -0800, Matimus wrote:
> > On Nov 13, 9:16 am, Joe Strout <[EMAIL PROTECTED]> wrote:
> > > One thing I miss as I move from REALbasic to Python is the ability to
> > > have static storage within a method --
On Thu, 2008-11-13 at 11:19 -0600, Chris Mellon wrote:
> On Thu, Nov 13, 2008 at 11:16 AM, Joe Strout <[EMAIL PROTECTED]> wrote:
> > One thing I miss as I move from REALbasic to Python is the ability to have
> > static storage within a method -- i.e. storage that is persistent between
> > calls, b
Joe Strout wrote:
> One thing I miss as I move from REALbasic to Python is the ability to
> have static storage within a method -- i.e. storage that is persistent
> between calls, but not visible outside the method. I frequently use
> this for such things as caching, or for keeping track of how ma
On Thu, 2008-11-13 at 09:38 -0800, Matimus wrote:
> On Nov 13, 9:16 am, Joe Strout <[EMAIL PROTECTED]> wrote:
> > One thing I miss as I move from REALbasic to Python is the ability to
> > have static storage within a method -- i.e. storage that is persistent
> > between calls, but not visible o
On Nov 13, 9:16 am, Joe Strout <[EMAIL PROTECTED]> wrote:
> One thing I miss as I move from REALbasic to Python is the ability to
> have static storage within a method -- i.e. storage that is persistent
> between calls, but not visible outside the method. I frequently use
> this for such thi
On Thu, Nov 13, 2008 at 11:16 AM, Joe Strout <[EMAIL PROTECTED]> wrote:
> One thing I miss as I move from REALbasic to Python is the ability to have
> static storage within a method -- i.e. storage that is persistent between
> calls, but not visible outside the method. I frequently use this for su
One thing I miss as I move from REALbasic to Python is the ability to
have static storage within a method -- i.e. storage that is persistent
between calls, but not visible outside the method. I frequently use
this for such things as caching, or for keeping track of how many
objects a facto
42 matches
Mail list logo