Singleton?

Jason Orendorff jason at jorendorff.com
Wed Jan 30 03:04:29 CET 2002


James T. Dennis wrote:
>  Now, unto other patterns.  Anyone show me an example of a flyweight?

The way Python strings work is reminiscent of Flyweight.

If you have

  x = "squoob"
  y = x[0]

then Python assigns to y one of its cached 1-character string
objects.  Thus grabbing individual characters out of a string
does not ordinarily create new string objects.  (But x does
not maintain pointers to 6 subobjects.  So it's not a real
Flyweight.  It's only a cache after all.)

Of course, this isn't at all what you asked for. (C:

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list