debug.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import re
  5. from cached_property import cached_property
  6. from pathlib import Path
  7. from module.logger import logger
  8. def remove_symbols(text):
  9. return re.sub(r'[^\w\s]', '', text)
  10. class Debugger:
  11. @cached_property
  12. def fn(self):
  13. # 以添加方式打开一个文件
  14. file: Path = Path(f'./log/quiz/supplement.txt')
  15. if not file.parent.exists():
  16. file.parent.mkdir(parents=True)
  17. if not file.exists():
  18. file.touch()
  19. f = open(str(file), 'a')
  20. return f
  21. def append_one(self, question: str, options: list[str]):
  22. question = remove_symbols(question)
  23. options = [remove_symbols(option) for option in options]
  24. self.fn.write(f'{question},{options[0]},{options[1]},{options[2]},{options[3]}\n')
  25. def close_fn(self):
  26. self.fn.close()
  27. if __name__ == '__main__':
  28. a = Debugger()
  29. a.append_one('1', ['1', '2', '3', '4'])
  30. a.append_one('5', ['1', '2939/;.', '3', '4'])
  31. a.append_one('1', ['1', '2', '3', '4'])
  32. a.close_fn()