###cfg.ini
[DEFAULT]
conn_str = %(dbn)s://%(user)s:%(pw)s@%(host)s:%(port)s/%(db)s
dbn = mysql
user = root
host=192.168.127.2
port = 3306
[db1]
user = test1
pw=test_123
db=ucds_1
[db2]
user = test2
host=192.168.127.1
pw=test_123
db=ucds_2
port=3308
conf = configparser.ConfigParser()
conf.read('cfg.ini')
print("mysql conn",conf.get('db1', 'conn_str'))
print("mysql conn",conf.get('db2', 'conn_str'))
##输出
mysql conn mysql://test1:[email protected]:3306/ucds_1
mysql conn mysql://test2:[email protected]:3308/ucds_2
##
用mixin模式让程序更加灵活
ruby复制代码
class TelMixin:
def telfunc(self, num):
self.name = num
print("call Phone ",self.name)
class SmsMixin:
def smsfunc(self, num):
self.name = num
print("send Sms info:",self.name)
class SongMixin:
def songfunc(self):
print("我可以放音乐")
class Phone(TelMixin,SmsMixin,SongMixin):
def __init__(self):
pass
class Ipod(SongMixin):
def __init__(self, sn):
self.num = num
p = Phone()
p.telfunc("110")
p.smsfunc("110")
p.songfunc()
静态代码分析工具
它可以帮助开发者检查代码中的错误、编码规范问题以及代码风格问题
sql复制代码
[devops@my-dev ccod_check_back_info]$ pip install pylint
[devops@my-dev ccod_check_back_info]$ pylint atest.py
************* Module atest
atest.py:5:17: C0303: Trailing whitespace (trailing-whitespace)
atest.py:7:0: C0301: Line too long (119/100) (line-too-long)
atest.py:9:0: C0301: Line too long (170/100) (line-too-long)
atest.py:1:0: C0114: Missing module docstring (missing-module-docstring)
atest.py:4:0: C0116: Missing function or method docstring (missing-function-docstring)
atest.py:17:0: C0116: Missing function or method docstring (missing-function-docstring)
atest.py:19:4: C0103: Variable name "Passwd" doesn't conform to snake_case naming style (invalid-name)
atest.py:22:12: C0103: Variable name "Passwd" doesn't conform to snake_case naming style (invalid-name)
-----------------------------------