将内容写入文件 :param file_path: :param section_name: :param section_dict: :param comment_str: :return:
(self, file_path, section_name, section_dict, comment_str=None)
| 54 | |
| 55 | class ConfigWriter(object): |
| 56 | def write(self, file_path, section_name, section_dict, comment_str=None): |
| 57 | """ |
| 58 | 将内容写入文件 |
| 59 | :param file_path: |
| 60 | :param section_name: |
| 61 | :param section_dict: |
| 62 | :param comment_str: |
| 63 | :return: |
| 64 | """ |
| 65 | context = "" |
| 66 | if comment_str: |
| 67 | context += comment_str |
| 68 | context += "\n" |
| 69 | |
| 70 | context += "[%s]\n" % section_name |
| 71 | |
| 72 | for key, value in section_dict.items(): |
| 73 | line = format(key, '<12') + ": " |
| 74 | if value: |
| 75 | line += value |
| 76 | line += "\n" |
| 77 | context += line |
| 78 | |
| 79 | with open(file_path, 'w') as wf: |
| 80 | wf.write(context) |
| 81 | |
| 82 | |
| 83 |
no outgoing calls
no test coverage detected