-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileWriter.py
More file actions
35 lines (31 loc) · 896 Bytes
/
FileWriter.py
File metadata and controls
35 lines (31 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# coding=utf-8
from LogTool import logger
class FileWriter(object):
"""
写文件
"""
@staticmethod
def writeline_with_endl(fp, content, num=2):
"""
带换行写内容
:param num: 换行个数
:param fp: 文件对象
:param content: 要写入的内容
"""
if content is not None:
fp.write(content + '\n' * num)
else:
logger.info("empty content")
@staticmethod
def writelines_with_endl(fp, contents, num=1):
"""
带换行写多行内容
:param fp: 文件对象
:param contents: 要写入的多行内容,列表
"""
if contents is not None:
for line in contents:
fp.write(line + '\n' * num)
else:
logger.info("empty content")