Re: Why can not initialize the class?
On 23/08/2014 1:17 AM, Steven D'Aprano wrote: Luofeiyu, you are getting stuck on basic questions. Before working with advanced features like properties, you should learn the simply features. Has luofeiyu ever actually acknowledged any such comment or request people have made? I see we've given up on trying to get em to stop top-posting, so I'm guessing no. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
On 23-08-14 01:20, Terry Reedy wrote: On 8/22/2014 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() By posting code with an extra indent, you make it imposible to run by just cutting and pasting. You should already know that. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
On 23-08-14 01:20, Terry Reedy wrote: On 8/22/2014 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() By posting code with an extra indent, you make it imposible to run by just cutting and pasting. You should already know that. I think your priorities are off. I often enought see people posting code that was copy-pasted from an interactive python session complete with lines beginning with . As far as I know nobody has complained about that even if it needs more manipulation before you can run the code than an extra indent. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
I edit it in the vim in well formatted form,when copied into email ,the format changed ,i don't know why. My email editor is thunderbird, you can try it as i say. I didn't mean to . By posting code with an extra indent, you make it imposible to run by just cutting and pasting. You should already know that. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
You can copy it into vim,and input :% ,the codes will be changed into well formatted. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
On Saturday, August 23, 2014 7:29:44 AM UTC+8, luofeiyu wrote: 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 . Well, an object in python can add properties in the run-time to evolve steadily and stealthly. Those unnessary set-get-C++ methods are not very important in PYTHON. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
On 08/23/2014 11:25 AM, CHIN Dihedral wrote: Well, an object in python can add properties in the run-time to evolve steadily and stealthly. Those unnessary set-get-C++ methods are not very important in PYTHON. That's the most coherent thing I've seen from Dihedral in years! -- https://mail.python.org/mailman/listinfo/python-list
Why can not initialize the class?
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 stdin, line 1, in module File stdin, line 7, in __init__ File stdin, line 11, in set_email TypeError: argument of type 'NoneType' is not iterable What is wrong with the code? -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
On Fri, Aug 22, 2014 at 10:26 AM, luofeiyu elearn2...@gmail.com 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 stdin, line 1, in module File stdin, line 7, in __init__ File stdin, 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. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
how to fix the code then? On 8/22/2014 10:36 PM, Larry Martell wrote: The 'in' operator requires an iterable. When you do 'self.email = email' set_email gets called and value is None. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
On Fri, Aug 22, 2014 at 10:42 AM, luofeiyu elearn2...@gmail.com wrote: how to fix the code then? On 8/22/2014 10:36 PM, Larry Martell wrote: The 'in' operator requires an iterable. When you do 'self.email = email' set_email gets called and value is None. You might want to set your default values to instead of none. When you create an instance of Contact, you should pass the first name, last name, and email address. -- https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
On Fri, Aug 22, 2014 at 10:58 AM, luofeiyu elearn2...@gmail.com wrote: class Contact(object): ... def __init__(self, first_name=None, last_name=None, ... display_name=None, email=haha@haha): ... 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): ... print(value) ... self._email = value ... def get_email(self): ... return self._email ... email = property(get_email, set_email) ... contact = Contact() haha@haha why the value in `def set_email(self, value): ` is haha@haha? how haha@haha is called to value in `def set_email(self, value): `? would you mind telling me the process? https://docs.python.org/3.4/library/functions.html#property -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
class Contact(object): ... def __init__(self, first_name=None, last_name=None, ... display_name=None, email=haha@haha): ... 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): ... print(value) ... self._email = value ... def get_email(self): ... return self._email ... email = property(get_email, set_email) ... contact = Contact() haha@haha why the value in `def set_email(self, value): ` is haha@haha? how haha@haha is called to value in `def set_email(self, value): `? would you mind telling me the process? -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
Luofeiyu, you are getting stuck on basic questions. Before working with advanced features like properties, you should learn the simply features. luofeiyu wrote: class Contact(object): ... def __init__(self, first_name=None, last_name=None, ... display_name=None, email=haha@haha): ... 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): ... print(value) ... self._email = value ... def get_email(self): ... return self._email ... email = property(get_email, set_email) ... contact = Contact() haha@haha why the value in `def set_email(self, value): ` is haha@haha? how haha@haha is called to value in `def set_email(self, value): `? would you mind telling me the process? Instead of this complicated example, start with this simple example: class Contact(object): def __init__(self, email=haha@haha): self.email = email contact = Contact() print(contact.email) Do you understand how contact.email gets set to haha@haha? Now let's make it a bit more complicated: class Contact(object): def __init__(self, email=haha@haha): self.set_email(email) def set_email(self, value): self.email = value contact = Contact() print(contact.email) Do you still understand how contact.email gets set to haha@haha? 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) Now do you understand how contact.email gets set to haha@haha? -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
On 8/22/2014 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() By posting code with an extra indent, you make it imposible to run by just cutting and pasting. You should already know that. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
Terry Reedy tjre...@udel.edu writes: By posting code with an extra indent, you make it imposible to run by just cutting and pasting. You should already know that. I commonly do that, as I do with most block quotes in plain text. I think it's a reasonable expectation that programmers, reading a forum about program code, will have at hand a programmer's editor capable of stripping a level of indentation from a block of code. -- \ “Cross country skiing is great if you live in a small country.” | `\—Steven Wright | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
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 . -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
On 8/22/2014 7:28 PM, Ben Finney wrote: Terry Reedy tjre...@udel.edu writes: By posting code with an extra indent, you make it imposible to run by just cutting and pasting. You should already know that. I commonly do that, It is unnecessary and extra work on both ends. It is also ambiguous in that there may be a missing unindented line. as I do with most block quotes in plain text. Code is not text, especially not python code. Indents do not change the meaning of text. I think it's a reasonable expectation that programmers, reading a forum about program code, will have at hand a programmer's editor capable of stripping a level of indentation from a block of code. Well yes, people here generally have Idle at hand, which can do it easily. However, it is unreasonable (and counterfactual -- see other thread today) to expect everyone to know that, or remember if they ever did know. It also requires that one get *all* the indentation and not miss the first space. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list