Commit da5513ab by “安晓东”

第九次作业

parent ec36c835
import os
#
dirnum = 0
filenum = 0
path = '/workspace/ai_project/9-Lesson11/nine_lesson'
for lists in os.listdir(path): # os.listdir(dirname):列出dirname下的目录和文件
sub_path = os.path.join(path, lists) # os.path.join(path,name):连接目录与文件名或目录
if os.path.isfile(sub_path): # os.path.isfile(name):判断name是不是一个文件,不存在name也返回false
print('文件===' + sub_path)
filenum = filenum + 1
elif os.path.isdir(sub_path): # os.path.isdir(name):判断name是不是一个目录,name不是目录就返回false
print('文件夹'+sub_path)
for i in os.listdir(sub_path):
print('\t'+lists + '文件夹下的文件:' + i)
dirnum = dirnum + 1
print('dirnum: ', dirnum)
print('filenum: ', filenum)
class Solution(object):
def deleteNode(self, head, node):
if node in head:
head.remove(node)
return head
if __name__ == '__main__':
s = Solution()
print(s.deleteNode([2, 3, 5, 6], 5))
# Nim游戏
class Solution(object):
def canWinNim(self, n):
return False if n % 4 == 0 else True
from lession_9.homework.operation_excel import OperationExcel
import time
from dateutil import rrule
import datetime
from lession_9.user_log import User_log
import logging
class ClaculateWages:
def __init__(self, file_name, sheet_name, staff_num: int = 0, staff_cut_off_time: str = '',
staff_name: str = '', staff_info: str = '', tation: str = '', tation_and_salary: list = '',
exception: str = '', total_sala: str = '', start_time: str = '', end_time: str = ''):
self.staff_num = staff_num # 员工编号
self.staff_cut_off_time = staff_cut_off_time # 工资算时间
self.staff_name = staff_name # 员工姓名
self.staff_info = staff_info # 员工基本信息结
self.tation_salar = tation_and_salary
self.tation = tation # 岗位
self.exception = exception # 说明
self.total_sala = total_sala # 工资总计
self.start_time = start_time
self.end_time = end_time
self.poer = OperationExcel(file_name, sheet_name)
u = User_log()
self.logger = u.set_log_config()
# 讲计算结果写入excel
def write_info(self):
self.salary_num()
try:
self.data = {
"员工编号": self.staff_num,
"工资结算时间": self.staff_cut_off_time,
"员工姓名": self.staff_name,
"员工基本信息": self.staff_info,
"岗位": self.tation,
"工资": self.tat_sala,
"说明": self.exception,
"工资总计": self.salary_num(),
}
except AttributeError:
pass
lis = []
try:
for li in self.data.values():
lis.append(li)
num = self.poer.get_lines()
print(num)
for i in range(len(lis)):
if self.salary_num() > 0:
self.poer.write_excel(num, i, lis[i])
if self.poer.get_cell_data(num, 2) == self.poer.get_cell_data(num - 1, 2):
total = int(self.poer.get_cell_data(num - 1, 7)) + self.salary_num()
self.poer.write_excel(num, 7, str(total))
if i == len(lis) - 1:
lis[i] = ""
self.poer.write_excel(num - 1, 7, lis[i])
except AttributeError as e:
logging.error('岗位名称不合法' + '--->' +self.tation+' '+ str(e))
# 计算工资
def salary_num(self):
try:
if self.tation == '程序员':
self.tat_sala = self.tation_salar[0][self.tation]
if self.tation == '扫地':
self.tat_sala = self.tation_salar[1][self.tation]
if (self.days_between() // 7) >= 1:
sala = round(self.tat_sala * (self.days_between() / 7))
return sala
else:
return 0
except AttributeError:
pass
# 计算工作时间
def days_between(self):
days = rrule.rrule(rrule.DAILY, dtstart=self.start_time, until=self.end_time)
return days.count()
if __name__ == '__main__':
c = ClaculateWages('员工工资表.xls', 'Sheet1')
c.staff_num = 3
c.staff_cut_off_time = '2019-01-01'
c.staff_name = '王五'
c.staff_info = '居住在回龙观 '
c.start_time = datetime.date(2019, 1, 1)
c.end_time = datetime.date(2019, 1, 12)
c.tation_salar = [{"程序员": 2000}, {"扫地": 1000}]
c.tation ='程序员'
c.exception = '工资结算4周'
c.write_info()
# c.staff_num = 4
# c.staff_cut_off_time = '2019-01-01'
# c.staff_name = '小h'
# c.staff_info = '居住在回龙观 '
# c.start_time = datetime.date(2019, 1, 1)
# c.end_time = datetime.date(2019, 1, 31)
# c.tation_salar = [{"程序员": 2000}, {"扫地": 1000}]
# c.tation = '扫地'
# c.exception = '工资结算4周'
# print(c.write_info())
# 1、定义一个函数,接受两个参数,第一个参数是原始图片文件,第二个参数是复制到的路径
import shutil
import os
def copy_image(source_file,target_path):
file_list = os.listdir(target_path)# 显示当前路径下的所有的文件和文件夹
for image in file_list:
#如果图像名为B.png 则将B.png复制到F:\\Test\\TestA\\class
if image == source_file:
if os.path.exists(os.path.join(target_path,'test')):
shutil.copy(os.path.join(target_path,image), os.path.join(target_path, 'test'))
print('复制成功')
else:
os.makedirs(os.path.join(target_path,'test'))
shutil.copy(os.path.join(target_path, image), os.path.join(target_path, 'test'))
copy_image('123.png', r'/workspace/ai_project/lession_9/homework')
\ No newline at end of file
import os
from lession_9.user_log import User_log
import logging
class Getfiels:
def __init__(self):
u = User_log()
self.logger = u.set_log_config()
def get_files(self, file_path):
dirnum = 0
filenum = 0
try:
for lists in os.listdir(path): # os.listdir(dirname):列出dirname下的目录和文件
sub_path = os.path.join(path, lists) # os.path.join(path,name):连接目录与文件名或目录
if os.path.isfile(sub_path): # os.path.isfile(name):判断name是不是一个文件,不存在name也返回false
filenum = filenum + 1
logging.info('文件-' + str(filenum) + sub_path)
elif os.path.isdir(sub_path): # os.path.isdir(name):判断name是不是一个目录,name不是目录就返回false
logging.info('文件夹' + sub_path)
for i in os.listdir(sub_path):
dirnum = dirnum + 1
logging.info('\t' + lists + '文件夹下的文件-' + i)
except FileNotFoundError as e:
logging.error(e)
return e
if __name__ == '__main__':
g = Getfiels()
path = '/workspace/ai_project/9-Lesson11/nine_lesson'
g.get_files(path)
import os
from xmlrpc.client import boolean
import xlrd
from xlutils.copy import copy
class OperationExcel:
def __init__(self, excel_file: str, sheet_name: str, ):
self.excel_fiel = excel_file
self.sheet_name = sheet_name
self.data = self.read_excel()
# 读取excel数据
def read_excel(self) -> str:
try:
data = xlrd.open_workbook(self.excel_fiel)
sheet = data.sheet_by_name(self.sheet_name)
return sheet
except FileNotFoundError as e:
print(e)
# 获取excel的某一行的内容
def get_rows(self, row):
return self.data.row_values(row)
# 获取某一列的内容
def get_rols(self, col):
return self.data.col_values(col)
# 获取excel单元格的内容
def get_cell_data(self, row, col):
try:
return self.data.cell_value(row, col)
except IndexError:
return 0
# excel 写入数据
def write_excel(self, row_num: int = 0, col_num: int = 0, content: str = '') -> boolean:
try:
read_data = xlrd.open_workbook(self.excel_fiel)
write_data = copy(read_data)
sheet_data = write_data.get_sheet(self.sheet_name)
sheet_data.write(row_num, col_num, content)
write_data.save(self.excel_fiel)
except FileNotFoundError as e:
print(e)
print(self.get_cell_data(row_num, col_num))
if self.get_cell_data(row_num, col_num) == content:
return True
else:
return False
# 获取行数
def get_lines(self):
try:
data = xlrd.open_workbook(self.excel_fiel)
sheet = data.sheet_by_name(self.sheet_name)
return sheet.nrows
except FileNotFoundError as e:
print('没有找到文件' + str(e))
if __name__ == '__main__':
o = OperationExcel('员工工资表.xls', 'Sheet1')
# print(o.get_rows(2))
print(o.get_cell_data(0, 8))
# print(o.get_rols(2))
# print(o.write_excel(4,4,'大家好'))
# print(o.write_excel(4,5,'海阔天空'))
o.get_lines()
# filename 是你要填写的日志路径及文件名称
filename = my-test.log
# 这是贪心学院的存储的日志
#www.greedyai.logpath = greedyai.log
# 测试环境的地址
#test_address = http://testscm.csjmro.com/#/salecontract/salecontractdetail/C000177 %(lineno)d
level = DEBUG # 这是日志的等级设置
format=%(asctime)s - %(levelname)s - %(funcName)s - %(lineno)d - %(message)s
\ No newline at end of file
2019-01-26 13:29:06,470 - INFO - 文件-1/workspace/ai_project/9-Lesson11/nine_lesson/exception.py
2019-01-26 13:29:06,470 - INFO - 文件-2/workspace/ai_project/9-Lesson11/nine_lesson/log_operation.py
2019-01-26 13:29:06,470 - INFO - 文件-3/workspace/ai_project/9-Lesson11/nine_lesson/1.txt
2019-01-26 13:29:06,470 - INFO - 文件-4/workspace/ai_project/9-Lesson11/nine_lesson/file_operation.py
2019-01-26 13:29:06,470 - INFO - 文件夹/workspace/ai_project/9-Lesson11/nine_lesson/company_log
2019-01-26 13:29:06,471 - INFO - company_log文件夹下的文件-__pycache__
2019-01-26 13:29:06,471 - INFO - company_log文件夹下的文件-use_log.py
2019-01-26 13:29:06,471 - INFO - company_log文件夹下的文件-properties_utils.py
2019-01-26 13:29:06,471 - INFO - company_log文件夹下的文件-log.properties
2019-01-26 13:29:06,471 - INFO - company_log文件夹下的文件-use_log2.py
2019-01-26 13:29:06,471 - INFO - company_log文件夹下的文件-my-test.log
2019-01-26 13:29:06,471 - INFO - company_log文件夹下的文件-__init__.py
2019-01-26 13:29:06,471 - INFO - 文件-5/workspace/ai_project/9-Lesson11/nine_lesson/my_test.log
2019-01-26 13:29:06,471 - INFO - 文件-6/workspace/ai_project/9-Lesson11/nine_lesson/my.log
2019-01-26 13:49:52,758 - INFO -get_files- 文件-1/workspace/ai_project/9-Lesson11/nine_lesson/exception.py
2019-01-26 13:49:52,758 - INFO -get_files- 文件-2/workspace/ai_project/9-Lesson11/nine_lesson/log_operation.py
2019-01-26 13:49:52,758 - INFO -get_files- 文件-3/workspace/ai_project/9-Lesson11/nine_lesson/1.txt
2019-01-26 13:49:52,758 - INFO -get_files- 文件-4/workspace/ai_project/9-Lesson11/nine_lesson/file_operation.py
2019-01-26 13:49:52,758 - INFO -get_files- 文件夹/workspace/ai_project/9-Lesson11/nine_lesson/company_log
2019-01-26 13:49:52,759 - INFO -get_files- company_log文件夹下的文件-__pycache__
2019-01-26 13:49:52,759 - INFO -get_files- company_log文件夹下的文件-use_log.py
2019-01-26 13:49:52,759 - INFO -get_files- company_log文件夹下的文件-properties_utils.py
2019-01-26 13:49:52,759 - INFO -get_files- company_log文件夹下的文件-log.properties
2019-01-26 13:49:52,759 - INFO -get_files- company_log文件夹下的文件-use_log2.py
2019-01-26 13:49:52,759 - INFO -get_files- company_log文件夹下的文件-my-test.log
2019-01-26 13:49:52,759 - INFO -get_files- company_log文件夹下的文件-__init__.py
2019-01-26 13:49:52,759 - INFO -get_files- 文件-5/workspace/ai_project/9-Lesson11/nine_lesson/my_test.log
2019-01-26 13:49:52,759 - INFO -get_files- 文件-6/workspace/ai_project/9-Lesson11/nine_lesson/my.log
2019-01-26 13:50:32,556 - INFO -get_files- 文件-1/workspace/ai_project/9-Lesson11/nine_lesson/exception.py
2019-01-26 13:50:32,556 - INFO -get_files- 文件-2/workspace/ai_project/9-Lesson11/nine_lesson/log_operation.py
2019-01-26 13:50:32,556 - INFO -get_files- 文件-3/workspace/ai_project/9-Lesson11/nine_lesson/1.txt
2019-01-26 13:50:32,556 - INFO -get_files- 文件-4/workspace/ai_project/9-Lesson11/nine_lesson/file_operation.py
2019-01-26 13:50:32,557 - INFO -get_files- 文件夹/workspace/ai_project/9-Lesson11/nine_lesson/company_log
2019-01-26 13:50:32,557 - INFO -get_files- company_log文件夹下的文件-__pycache__
2019-01-26 13:50:32,557 - INFO -get_files- company_log文件夹下的文件-use_log.py
2019-01-26 13:50:32,557 - INFO -get_files- company_log文件夹下的文件-properties_utils.py
2019-01-26 13:50:32,557 - INFO -get_files- company_log文件夹下的文件-log.properties
2019-01-26 13:50:32,557 - INFO -get_files- company_log文件夹下的文件-use_log2.py
2019-01-26 13:50:32,557 - INFO -get_files- company_log文件夹下的文件-my-test.log
2019-01-26 13:50:32,557 - INFO -get_files- company_log文件夹下的文件-__init__.py
2019-01-26 13:50:32,557 - INFO -get_files- 文件-5/workspace/ai_project/9-Lesson11/nine_lesson/my_test.log
2019-01-26 13:50:32,558 - INFO -get_files- 文件-6/workspace/ai_project/9-Lesson11/nine_lesson/my.log
2019-01-27 12:58:19,046 - ERROR -get_files- 没有找到文件
2019-01-27 13:01:24,853 - ERROR -get_files- [Errno 2] No such file or directory: '/workspace/ai_project/9-Lesson11/nine_lesson1'
2019-01-27 13:01:41,963 - ERROR -get_files- [Errno 2] No such file or directory: '/workspace/ai_project/9-Lesson11/nine_lesson1'
2019-01-27 13:03:22,516 - INFO -get_files- 文件-1/workspace/ai_project/9-Lesson11/nine_lesson/exception.py
2019-01-27 13:03:22,516 - INFO -get_files- 文件-2/workspace/ai_project/9-Lesson11/nine_lesson/log_operation.py
2019-01-27 13:03:22,516 - INFO -get_files- 文件-3/workspace/ai_project/9-Lesson11/nine_lesson/1.txt
2019-01-27 13:03:22,516 - INFO -get_files- 文件-4/workspace/ai_project/9-Lesson11/nine_lesson/file_operation.py
2019-01-27 13:03:22,517 - INFO -get_files- 文件夹/workspace/ai_project/9-Lesson11/nine_lesson/company_log
2019-01-27 13:03:22,517 - INFO -get_files- company_log文件夹下的文件-__pycache__
2019-01-27 13:03:22,517 - INFO -get_files- company_log文件夹下的文件-use_log.py
2019-01-27 13:03:22,517 - INFO -get_files- company_log文件夹下的文件-properties_utils.py
2019-01-27 13:03:22,517 - INFO -get_files- company_log文件夹下的文件-log.properties
2019-01-27 13:03:22,517 - INFO -get_files- company_log文件夹下的文件-use_log2.py
2019-01-27 13:03:22,517 - INFO -get_files- company_log文件夹下的文件-my-test.log
2019-01-27 13:03:22,517 - INFO -get_files- company_log文件夹下的文件-__init__.py
2019-01-27 13:03:22,517 - INFO -get_files- 文件-5/workspace/ai_project/9-Lesson11/nine_lesson/my_test.log
2019-01-27 13:03:22,517 - INFO -get_files- 文件-6/workspace/ai_project/9-Lesson11/nine_lesson/my.log
2019-01-28 13:38:42,791 - INFO -get_files- 文件-1/workspace/ai_project/9-Lesson11/nine_lesson/exception.py
2019-01-28 13:38:42,792 - INFO -get_files- 文件-2/workspace/ai_project/9-Lesson11/nine_lesson/log_operation.py
2019-01-28 13:38:42,793 - INFO -get_files- 文件-3/workspace/ai_project/9-Lesson11/nine_lesson/1.txt
2019-01-28 13:38:42,794 - INFO -get_files- 文件-4/workspace/ai_project/9-Lesson11/nine_lesson/file_operation.py
2019-01-28 13:38:42,795 - INFO -get_files- 文件夹/workspace/ai_project/9-Lesson11/nine_lesson/company_log
2019-01-28 13:38:42,796 - INFO -get_files- company_log文件夹下的文件-__pycache__
2019-01-28 13:38:42,797 - INFO -get_files- company_log文件夹下的文件-use_log.py
2019-01-28 13:38:42,797 - INFO -get_files- company_log文件夹下的文件-properties_utils.py
2019-01-28 13:38:42,798 - INFO -get_files- company_log文件夹下的文件-log.properties
2019-01-28 13:38:42,799 - INFO -get_files- company_log文件夹下的文件-use_log2.py
2019-01-28 13:38:42,799 - INFO -get_files- company_log文件夹下的文件-my-test.log
2019-01-28 13:38:42,800 - INFO -get_files- company_log文件夹下的文件-__init__.py
2019-01-28 13:38:42,801 - INFO -get_files- 文件-5/workspace/ai_project/9-Lesson11/nine_lesson/my_test.log
2019-01-28 13:38:42,801 - INFO -get_files- 文件-6/workspace/ai_project/9-Lesson11/nine_lesson/my.log
2019-01-29 22:33:58,040 - ERROR - write_info - 60 - 岗位名称不合法--->'ClaculateWages' object has no attribute 'data'
2019-01-29 23:32:15,642--INFO--get_log--31--这是一个info级别的日志
2019-01-29 23:32:15,642--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-29 23:32:15,643--DEBUG--get_log--33--这是一个debug级别的日志
2019-01-29 23:34:04,909--INFO--get_log--31--这是一个info级别的日志
2019-01-29 23:34:04,909--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-29 23:34:04,909--DEBUG--get_log--33--这是一个debug级别的日志
2019-01-29 23:34:04,910--INFO--use_log2_file--11--这是一个info级别的日志444444444444444444444444
2019-01-29 23:34:04,910--ERROR--use_log2_file--12--这是一个error级别的日志5555555555555555555555
2019-01-30 11:06:13,529 - INFO - write_info - 59 - 工作时长不能小于7
2019-01-30 11:12:58,307 - ERROR - write_info - 62 - 岗位名称不合法--->'ClaculateWages' object has no attribute 'data'
2019-01-30 11:45:11,588 - ERROR - write_info - 62 - 岗位名称不合法--->'ClaculateWages' object has no attribute 'data'
2019-01-30 11:45:53,862 - ERROR - write_info - 62 - 岗位名称不合法--->小f'ClaculateWages' object has no attribute 'data'
2019-01-30 11:46:36,634 - ERROR - write_info - 62 - 岗位名称不合法--->12 'ClaculateWages' object has no attribute 'data'
2019-01-30 11:52:06,008 - ERROR - write_info - 62 - 岗位名称不合法--->fdfdfdfd 'ClaculateWages' object has no attribute 'data'
2019-01-31 12:42:34,339--INFO--get_log--31--这是一个info级别的日志
2019-01-31 12:42:34,339--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-31 12:42:34,340--DEBUG--get_log--33--这是一个debug级别的日志
2019-01-31 12:43:13,793--INFO--get_log--31--这是一个info级别的日志
2019-01-31 12:43:13,793--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-31 12:43:13,793--DEBUG--get_log--33--这是一个debug级别的日志
2019-01-31 12:43:19,214--INFO--get_log--31--这是一个info级别的日志
2019-01-31 12:43:19,215--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-31 12:43:19,215--DEBUG--get_log--33--这是一个debug级别的日志
2019-01-31 12:47:09,064 - ERROR - write_info - 67 - 岗位名称不合法--->程序员22 'ClaculateWages' object has no attribute 'data'
2019-01-31 12:47:39,000 - ERROR - write_info - 67 - 岗位名称不合法--->程序员121 'ClaculateWages' object has no attribute 'data'
2019-01-31 12:49:39,736 - INFO - write_info - 67 - 岗位名称不合法--->程序员22 'ClaculateWages' object has no attribute 'data'
这是一个错误级别的日志666666666666666666666
这是一个错误级别的日志666666666666666666666
这是一个error级别的日志5555555555555555555555
这是一个error级别的日志5555555555555555555555
2019-01-29 23:19:43,376 - ERROR - get_log - 26 - 这是一个错误级别的日志666666666666666666666
2019-01-29 23:22:09,743 - ERROR - get_log - 26 - 这是一个错误级别的日志666666666666666666666
2019-01-29 23:22:09,743 - ERROR - use_log2_file - 12 - 这是一个error级别的日志5555555555555555555555
2019-01-29 23:22:23,319 - ERROR - use_log2_file - 12 - 这是一个error级别的日志5555555555555555555555
2019-01-29 23:23:12,624--ERROR--use_log2_file--12--这是一个error级别的日志5555555555555555555555
2019-01-29 23:32:15,642--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-29 23:34:04,909--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-29 23:34:04,910--ERROR--use_log2_file--12--这是一个error级别的日志5555555555555555555555
2019-01-30 00:18:22,572--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-30 00:18:42,939--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-31 12:42:34,339--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-31 12:43:13,793--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-31 12:43:19,215--ERROR--get_log--32--这是一个错误级别的日志666666666666666666666
2019-01-29 22:25:20,108 - INFO - <module> - 35 - heheheheheheheheh
2019-01-29 22:28:37,359 - INFO - <module> - 38 - heheheheheheheheh
2019-01-29 22:29:15,828 - ERROR - <module> - 38 - heheheheheheheheh
2019-01-29 22:31:28,537 - ERROR - <module> - 38 - heheheheheheheheh
2019-01-29 22:32:12,043 - ERROR - <module> - 38 - heheheheheheheheh
import logging
import os
import datetime
class configlog:
def get_log(self):
self.logger = logging.getLogger()
self.logger.setLevel("DEBUG")
der = os.path.dirname(os.path.abspath(__file__))
log_dir = os.path.join(der, "logs")
log_file = datetime.datetime.now().strftime("%Y-%m-%d") + ".log"
log_name = log_dir + "/" + log_file
# 设置文件hender 这个设置是将内容输出到文件中
file_handler = logging.FileHandler(log_name, mode='a', encoding='utf-8')
# 流处理 输出到控制台
stream_hander = logging.StreamHandler()
# 将一个error文件输入到err.log的的文件中
error_handler = logging.FileHandler("/workspace/ai_project/lession_9/logs/error.log", mode='a',encoding='utf-8')
error_handler.setLevel(logging.ERROR)
self.logger.addHandler(file_handler)
self.logger.addHandler(error_handler)
self.logger.addHandler(stream_hander)
# 设置
formater = logging.Formatter(fmt="%(asctime)s--%(levelname)s--%(funcName)s--%(lineno)d--%(message)s")
file_handler.setFormatter(formater)
error_handler.setFormatter(formater)
stream_hander.setFormatter(formater)
self.logger.info('这是一个info级别的日志')
self.logger.error('这是一个错误级别的日志666666666666666666666')
self.logger.debug('这是一个debug级别的日志')
if __name__ == '__main__':
c = configlog()
c.get_log()
import os
class Properties1():
def __init__(self, file_name):
self.properties_file_name = file_name
self.properties = {}
def get_properties(self):
with open(self.properties_file_name, "r", encoding="utf-8") as f:
for line in f.readlines():
# 去掉两端的空格、换行符\n
line = line.strip().replace("\n", "")
# 如果发现 # 符号,代表这一行或后边是注释内容
if line.find("#") != -1:
line = line[0:line.find("#")]
# 如果包含了等号,我们就要进行字典类型的装换处理
if line.find("=") > 0:
strs = line.split("=")
self.__get_dict(strs[0].strip(), self.properties,strs[1].strip())
# print(self.properties)
return self.properties
def __get_dict(self,key_name, result_dict, value):
# 检查key中是否包含".",包含和话就切分,不包含的话就直接设置值
if (key_name.find(".") > 0):
k = key_name.split(".")[0]
result_dict.setdefault(k, {})
return self.__get_dict(key_name[len(k)+1:], result_dict[k], value)
else:
result_dict[key_name] = value
import logging
from lession_9.opration_log import configlog
class test1():
def __init__(self):
self.logger = configlog()
def use_log2_file(self):
self.logger.get_log()
logging.info('这是一个info级别的日志444444444444444444444444')
logging.error('这是一个error级别的日志5555555555555555555555')
if __name__ == '__main__':
te = test1()
te.use_log2_file()
\ No newline at end of file
from lession_9.properties_utils import Properties1
# from lession_9.use_log2 import test1
import logging
import os
import datetime
class User_log:
def set_log_config(self):
der = os.path.dirname(os.path.abspath(__file__))
pro = Properties1(der + '/' + 'log.properties').get_properties()
log_dir = os.path.join(der, "logs")
log_file = datetime.datetime.now().strftime("%Y-%m-%d") + ".log"
log_name = log_dir + "/" + log_file
log_config = {
"filename": log_name,
"level": pro["level"],
"format": pro["format"]
}
logging.basicConfig(**log_config)
def set_only_log_config(self):
der = os.path.dirname(os.path.abspath(__file__))
log_config = Properties1(der+'/'+'log.properties').get_properties()
logging.basicConfig(**log_config)
if __name__ == '__main__':
u = User_log()
u.set_only_log_config()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment