我正在使用 python 2.7,这是我所拥有的。
方法:
def get_phone(self):
digits = filter(str.isdigit, str(self.phone))
if re.match(r'(0|380)\d{9}', digits):
operator = digits[-9:-7]
digits = digits[-7:]
return "+380 ({}) {}".format(opeself.rator, digits)
return None
Run Code Online (Sandbox Code Playgroud)
现在,如果我像这样使用这种方法:
dictionary = {
'phone': User.get_phone()
}
Run Code Online (Sandbox Code Playgroud)
输出是:
{'phone': '+380 (12) 1234567'}
Run Code Online (Sandbox Code Playgroud)
但如果我像这样使用它:
dictionary['phone'] = User.get_phone(),
Run Code Online (Sandbox Code Playgroud)
输出变成一个元组:
{'phone': ('+380 (12) 1234567',)}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
python ×1