Object-Oriented Review 01

Object oriented acquaintance
1. functional programming characteristics of two oriented programming process
to reduce repetitive code
enhance readability of the code
2. The process-oriented programming object-oriented programming
2.1 What is object-oriented
core object-oriented programming object (God thinking), to understand why the object must regard themselves as God, all things are all objects exist in the eyes of the world God does not exist can be created.

2.2 What is class, what is the object
class: a class of things that have the same properties and functions.

Object: is a concrete manifestation of the class.

3. The structure of the class
class Human:
"" "
Such constructs mainly human
" ""
Mind = 'thinking' first part #: Static Properties Static variable static field
DIC} = {
L1 = []
DEF Work (Self) : # part II: method function dynamic properties
print ( 'work humans')
class use the same keyword def, define a class.
Human is a kind of class names, class names use camel (CamelCase) naming style, capitalized private classes available a leading underscore.
Class structure of the general direction to be divided into two parts: the
static variable.
Dynamic method.
From the class name perspective studies class
class Human:
"" "
concrete structural class of
" ""
# Part I: Static Property
mind = 'thinking' attribute # class (static properties, static fields)
Language = 'language'
# part II: dynamic method
DEF work (Self):
Print ( 'humans will work')
DEF eAT (Self):
Print ( 'humans need to eat'

  1. Class name attribute operation class
    1. Category name to view all the content in class
      print (Human .__ dict__)
    2. Static properties omnipotent point of the class name class operation.

By:
Human.body = 'heads and limbs have'
deleted:
del Human.mind
change:
Human.mind = 'liye brain damage'
investigation:
Print (Human.language)
Print (Human .__ dict__ magic)

  1. Class method name to call class ((static methods, class methods are generally class) method does not pass the class name calling)
    Human.work (111)

Summary:
General class name is the operation of the class attributes.
From the target angle studies class
Human class:
"" "
concrete structural class of
" ""
# Part I: Static Property
mind = 'thinking' properties (Static Property # class, static field)
language = 'language'
DEF the init (Self):
# Print (f'self ---->: Self {} ')
# Print (666)
the self.name =' Li industry '
self.age = 18 is

# 第二部分: 动态方法
def work(self):
    print('人类都会工作')

def eat(self):
    print('人类都需要吃饭')

obj = Human () # instantiation process
to obtain a return value, the return value is an object instance.
Print (f'obj ---> obj {} ')
to instantiate an object three things happen:
' ''
1 . a space to open.
2. __init__ method is performed automatically, and the address of the object passed to self.
Code in 3. run __init__ method, to the object space of the package properties.

'''

Human class:
"" "
category specific structure
" ""
# Part I: Static Property
mind = 'thinking' attribute # class (static properties, static fields)
Language = 'language'

def __init__(self, name, age):
    # print(f'self---->: {self}')
    # print(666)
    self.n = name
    self.a = age


# 第二部分: 动态方法
def work(self):
    # print(f'self---> {self}')
    print(f'{self.n}都会工作')


def eat(self):
    print(f'{self.n}都需要吃饭')

obj = Human ( 'Li industry', 18) the process of Example #
Print (obj.n)
Print (obj.a)
(.__ dict__ magic obj) Print
operation target object attribute space

  1. Object view all the properties of space object
    obj = Human ( 'Charles Lee', 18)
    Print (obj .__ dict__)
  2. Operation target space attribute object
    obj = Human ( 'Li industry', 18)
    by:
    obj.sex = 'laddy_boy'
    deleted:
    del obj.a
    change:
    obj.a = 1000
    investigation:
    Print (obj.n)
    Print (obj .__ dict__)
    properties of the object class to view
    obj = Human ( 'Li industry', 18)

    print(obj.mind)

    obj.mind = 'no brain'
    Print (obj.mind)
    Print (Human.mind)
    method call to an object class
    obj = Human ( 'Sun Dave', 23)

    print(f'obj---> {obj}')

    obj.work ()
    obj.eat ()
    a plurality of objects can be instantiated class
    obj1 = Human ( 'Li industry', 18)
    obj2 = Human ( 'small cute', 16)
    OBJ3 = Human ( 'dislike sister', 18 )

Variable and function names:
age_of_oldboy = 73
Ageofoldboy
logging Ultimate use
import logging.config

It defines three log output format beginning

standard_format = '[% (asctime) s] [% (threadName) s:% (thread) d] [task_id:% (name) s] [% (filename) s:% (lineno) d] [% (levelname) s] [% (message) s] '# where name is the name specified getlogger

simple_format = '在 %(asctime)s %(message)s'

id_simple_format = '[%(levelname)s][%(asctime)s] %(message)s'

The full path to the log file

logfile_path = 'all2.log'

log configuration dictionary

LOGGING_DIC = {
'Version':. 1,
'disable_existing_loggers': False,
'formatters': {
'Standard': {
'the format': standard_format
},
'Simple': {
'the format': simple_format
},
},
'Filters': } {,
'handlers': {
# print log to the terminal
'Stream': {
'Level': 'the DEBUG',
'class': 'logging.StreamHandler', printed to the screen #
'Formatter': 'Simple'
},
# print the log file, and collected more info log
'file': {
'Level': 'DEBUG',
'class':' logging.handlers.RotatingFileHandler ', # save to file
'Formatter ':' Standard ',
' filename ': None, # log file
' MaxBytes': 1024 1024 1024, # log size 5M
'BACKUPCOUNT':. 5,
'encoding': 'UTF-. 8', # encoding the log file, no longer have to worry about distortion Chinese log
},
},
'Loggers': {
# logging.getLogger ( name ) get logger configuration
'': {
'handlers': [ 'Stream', 'file'], where # the two above-defined handler are coupled, i.e., both the data written to log file to the screen printing and
'level': 'DEBUG' ,
'Propagate': True, # up (the higher level Logger) passing
}
}
}

get_logger DEF ():
path = R'f: \ S24 \ day21 \ liye.log '
LOGGING_DIC [' handlers'] [ 'File'] [ 'filename'] = path
logging.config.dictConfig (LOGGING_DIC) # Import defined above the logging configuration
Logger = logging.getLogger ( name ) to generate a log # instance
return logger

Save DEF ():
Logger = get_logger ()
logger.info (F '{} stored 300 yuan') # record operating state of the file

save()

Guess you like

Origin www.cnblogs.com/-777/p/11291422.html