Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea for metaprogramming lesson: #82

Open
PythonCHB opened this issue Dec 28, 2017 · 1 comment
Open

Idea for metaprogramming lesson: #82

PythonCHB opened this issue Dec 28, 2017 · 1 comment
Assignees

Comments

@PythonCHB
Copy link
Contributor

PythonCHB commented Dec 28, 2017

One of our students did the following properties to normalize the names of the Donors in mailroom.

Could that code repetition be avoided with some meta-programming?

 @property
    def first_name(self):
        """ return the first name """
        return self._first_name

    @first_name.setter
    def first_name(self, value):
        """ set the first name """
        self._first_name = value.title()

    @property
    def middle_name(self):
        """ return the middle name """
        return self._middle_name

    @middle_name.setter
    def middle_name(self, value):
        """ set the middle name """
        self._middle_name = value.title()

    @property
    def last_name(self):
        """ return the last name """
        return self._last_name

    @last_name.setter
    def last_name(self, value):
        """ set the last name """
        self._last_name = value.title()

    @property
    def suffix(self):
        """ return the suffix """
        return self._suffix
@PythonCHB PythonCHB added this to the Course 2: Advanced Python milestone Dec 28, 2017
@PythonCHB PythonCHB self-assigned this Dec 28, 2017
@PythonCHB
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant