Tôi cần phải biết tại sao điều này không:tuples và danh sách python. Một tuple mà từ chối để chuyển đổi
class ConfigurationError(Exception):
def __init__(self, *args):
super(ConfigurationError, self).__init__(self, args)
self.args = list(args)
# Do some formatting on the message string stored in self.args[0]
self.args[0]=self.__prettyfi(self.args[0])
def __prettyfi(self, arg):
pass
# Actual function splits message at word
# boundaries at pos rfind(arg[1:78]) if len(arg) >78
# it does this by converting a whitespace char to a \n
Khi tôi chạy mã này, tôi nhận được msg sau: <snip> ConfigurationError.py", line 7, in __init__ self.args[0]=self.__prettyfi(self.args[0]) TypeError: 'tuple' object does not support item assignment
Tôi chỉnh sửa các dòng không có. để phù hợp với mẫu mã này.
Tôi không hiểu tại sao self.args = list(args)
không giải nén một cách chính xác các tuple vào danh sách ở dòng 5.
(Tôi có một nghi ngờ lén Tôi không nhớ một cái gì đó siêu cơ bản ...)
Có bất kỳ lý do kỹ thuật nào tại sao nó là một bộ mô tả không? –
@Tinctorius: Ngoại lệ là không thay đổi và 'args' cũng phải là quá. Hơn nữa, 'Exception.args' được ghi nhận là một tuple. –
grrrrrrrrrrrr ... cảm ơn bạn. Đoán bệnh cho vòng lặp giải nén nó sau đó. Trừ khi ai đó biết một cách tốt hơn ....? – Jase