Skip to content

Instantly share code, notes, and snippets.

@Chestermozhao
Created July 7, 2020 12:49
Show Gist options
  • Save Chestermozhao/c87c3855d478b87c59f97255892d906c to your computer and use it in GitHub Desktop.
Save Chestermozhao/c87c3855d478b87c59f97255892d906c to your computer and use it in GitHub Desktop.
# -*- 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