Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'operator': 0.03; 'argument': 0.05; '22,': 0.09; '__init__': 0.09; 'subject:Why': 0.09; 'def': 0.12; 'code?': 0.16; 'display_name': 0.16; 'iterable': 0.16; 'none.': 0.16; 'subject:class': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'aug': 0.22; 'to:name:python- list@python.org': 0.22; 'error': 0.23; 'gets': 0.27; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'raise': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; 'file': 0.32; 'class': 0.32; '(most': 0.33; 'fri,': 0.33; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'received:google.com': 0.35; 'subject:?': 0.36; 'wrong': 0.37; 'to:addr:python-list': 0.38; 'recent': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'called': 0.40; 'contact': 0.67 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=p4D2CxGoFlhSwo8B9Gxl88IadOPb7nqz9diK+ApCLw4=; b=eUrasjRDKt8dywM90RxPSS0XG0uWJ9TmCefKHqDMphYU5sDOja+mKiEA9q27Xp0/QE VmXFtW5e8b7T4xwIeoLakRFIUN3zCG7DT6NEBw/xxDoSgRj7Gk0+CQQ8zQ5fPLJhiBHc BqsShYemiyHF1R0pHNZigUDWnGTntV/OSXf0eoouBVYUSWlUTVaugp4FrLlFQyNgbUt2 n+ADqgDdDVdtQrr3LpvNb2jNbKQDARQlNPqJIkmtMfL/cRbN8EPFbXSXJgwKMG7RTvR2 WW7qorgExw+pgJ0MZUwEXp19FchhChLOVmT3wl7CMiZkX7imUpfqPkSr6ZAEypPSztO4 BKIw== MIME-Version: 1.0 X-Received: by 10.180.72.146 with SMTP id d18mr7987183wiv.53.1408718160409; Fri, 22 Aug 2014 07:36:00 -0700 (PDT) In-Reply-To: <53F752FA.8080902@gmail.com> References: <53F752FA.8080902@gmail.com> Date: Fri, 22 Aug 2014 10:36:00 -0400 Subject: Re: Why can not initialize the class? From: Larry Martell To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408718166 news.xs4all.nl 2870 [2001:888:2000:d::a6]:40606 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76791 On Fri, Aug 22, 2014 at 10:26 AM, luofeiyu wrote: > System:win7+python34. > > class Contact(object): > def __init__(self, first_name=None, last_name=None, > display_name=None, email=None): > self.first_name = first_name > self.last_name = last_name > self.display_name = display_name > self.email = email > def print_info(self): > print(self.display_name, "<" + self.email + ">" ) > def set_email(self, value): > if '@' not in value: > raise Exception("This doesn't look like an email address.") > self._email = value > def get_email(self): > return self._email > email = property(get_email, set_email) > > contact = Contact() > > The error message is : > Traceback (most recent call last): > File "", line 1, in > File "", line 7, in __init__ > File "", line 11, in set_email > TypeError: argument of type 'NoneType' is not iterable > > What is wrong with the code? The 'in' operator requires an iterable. When you do 'self.email = email' set_email gets called and value is None.