when to use intern()
Michael Hudson
mwh21 at cam.ac.uk
Thu Apr 27 09:03:57 EDT 2000
Gregory Trubetskoy <grisha at ispol.com> writes:
> It says in the manual that some things in Python get interned
> automatically. I'm not sure where intern() is necessary -
Almost never.
> if I have a statement like:
>
> if self.config.has_key("PythonOption"):
> ...
>
> that gets executed a lot - should I consider interning "PythonOption" or
Well, you can, but...
> is it done automatically?
Yes.
>
> what about
>
> PYTHON_OPTION = "PythonOption"
> if self.config.has_key(PYTHON_OPTION):
> ...
>
> is this interned?
Yes.
See Python/compile.c in the source distribution round about line 240
for the gory details...
HTH,
Michael
--
48. The best book on programming for the layman is "Alice in
Wonderland"; but that's because it's the best book on
anything for the layman.
-- Alan Perlis, http://www.cs.yale.edu/~perlis-alan/quotes.html
More information about the Python-list
mailing list