Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中同时使用sys.intern(string)和NewType输入模块?_Python_String_Memory_Typing_Sys - Fatal编程技术网

在Python中同时使用sys.intern(string)和NewType输入模块?

在Python中同时使用sys.intern(string)和NewType输入模块?,python,string,memory,typing,sys,Python,String,Memory,Typing,Sys,一个人如何使用和在一起 import sys from typing import NewType UserName = NewType('UserName', str) username = UserName(sys.intern('awesome_repeated_name')) # or username = sys.intern(UserName('awesome_repeated_name')) 使用sys.intern()的目的是否实现了,即当使用NewType时,每次在内存中

一个人如何使用和在一起

import sys
from typing import NewType

UserName = NewType('UserName', str)

username = UserName(sys.intern('awesome_repeated_name'))
# or
username = sys.intern(UserName('awesome_repeated_name'))

使用
sys.intern()
的目的是否实现了,即当使用
NewType
时,每次在内存中显示一次字符串时,该字符串只存储一次?

为什么在这里使用
sys.intern
,想法是拥有一个唯一的内存分配。但是关于如何正确使用它,我可能是错的?