max*_*max 5 python object mutable
修改标准库对象的方法返回的可变对象是否安全?
这是一个具体的例子; 但如果可能的话,我正在寻找一般答案.
#m is a MatchObject
#I know there's only one named group in the regex
#I want to retrieve the name and the value
g, v = m.groupdict().popitem()
#do something else with m
这段代码安全吗?我担心通过改变groupdict()我会破坏对象m(我以后还需要它).
我对此进行了测试,随后对m.groupdict()的调用仍返回原始字典; 但据我所知,这可能与实现有关.