研究email源码学到的
class test(): """Class for generating text/* type MIME documents.""" def __init__(self): self._headers = [] def __getitem__(self, name, failobj=None): name = name.lower() for k, v in self._headers: if k.lower() == name: return v return failobj def __setitem__(self, name, val): self._headers.append((name, val)) def __str__(self): """Return the entire formatted message as a string. This includes the headers, body, and envelope header. """ return self.as_string() def as_string(self): return self._headers test1=test() test1['1']=2 print test1.as_string()