Created
July 7, 2020 12:49
-
-
Save Chestermozhao/c87c3855d478b87c59f97255892d906c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*- | |
class User(object): | |
bar = 1 | |
def __init__(self, name, age, height): | |
self.name = name | |
self.age = age | |
self.height = height | |
# this function didnt use other class property | |
@classmethod | |
def update_user(cls, name, age): | |
# ... | |
print("update {name}, {age}".format(name=name, age=age)) | |
pass | |
@classmethod | |
def create_or_update_user(cls, name, age): | |
try: | |
# insert data to datadabe | |
print('Insert user into user table') | |
# calling class parameters | |
print (cls.bar) | |
# if duplicate after inseting | |
except: | |
# calling update function | |
cls.update_user(name, age) | |
name = "Chester" | |
age = 25 | |
User.create_or_update_user(name, age) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment