On this page
sys.intern
Prev: sys.getunicodeinternedsize | Up: sys | Next: sys.is_finalizing
Rel: sys.activate_stack_trampoline, sys.addaudithook, sys.audit, sys.breakpointhook
Ref: docs.python.org — sys.intern
Tags: #public #python3 #stdlib #sys
Import
import sys
from sys import intern
Signature & Overview
sys.intern(string, /)
``Intern'' the given string.
Usage
import sys
a = sys.intern("shared_identifier_key")
b = sys.intern("shared_" + "identifier_key")
assert a is b
Gotchas
- Saves memory on millions of repeated strings: Allows fast
iscomparisons, but don't intern unbounded unique user strings—interned strings can live longer than expected.
REPL Inspect
from sys import intern
help(intern)
Linked from
Related notes
- tuts/python3/stdlib_module/sys/getunicodeinternedsize Linked here; links to this page; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/is_finalizing Linked here; links to this page; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sys/activate_stack_trampoline Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/addaudithook Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/audit Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/breakpointhook Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/call_tracing shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/deactivate_stack_trampoline shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/displayhook shared tags: #stdlib, #sys