Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76832

Re: Why can not initialize the class?

Date 2014-08-23 07:29 +0800
From luofeiyu <elearn2014@gmail.com>
Subject Re: Why can not initialize the class?
References (1 earlier) <CACwCsY5P_8OUma6yMJxNCDd1WHtNrM0_ck2oebLv3mpPF20WCQ@mail.gmail.com> <53F756BF.1030100@gmail.com> <CAPM-O+wJi-ZLUyP+E=9DP+gje8k0O04nP6yuhrG75f2oQTMJZQ@mail.gmail.com> <mailman.13293.1408719557.18130.python-list@python.org> <53f75f22$0$6512$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.13318.1408750213.18130.python-list@python.org> (permalink)

Show all headers | View raw


One final version:

class Contact(object):
     def __init__(self, email="haha@haha"):
         self.email = email
     def _get_email(self):
         return self._the_secret_private_email
     def _set_email(self, value):
         self.self._the_secret_private_email = value
     email = property(_get_email, _set_email)

contact = Contact()
print(contact.email)

There is a little mistake here. It is

self._the_secret_private_email = value

not

self.self._the_secret_private_email = value

think for your demo .The value in `def _set_email(self, value):` is the value of self.email .

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Why can not initialize the class? luofeiyu <elearn2014@gmail.com> - 2014-08-22 22:58 +0800
  Re: Why can not initialize the class? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-23 01:17 +1000
    Re: Why can not initialize the class? luofeiyu <elearn2014@gmail.com> - 2014-08-23 07:29 +0800
      Re: Why can not initialize the class? CHIN Dihedral <dihedral88888@gmail.com> - 2014-08-23 10:25 -0700
        Re: Why can not initialize the class? Michael Torrie <torriem@gmail.com> - 2014-08-23 20:03 -0600
    Re: Why can not initialize the class? alex23 <wuwei23@gmail.com> - 2014-08-25 16:33 +1000

csiph-web