datasets.py 953 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- coding:utf-8 -*-
  2. # !/usr/bin/env python
  3. """
  4. Date: 2024/12/30 15:30
  5. Desc: 导入文件工具,可以正确处理路径问题
  6. """
  7. import pathlib
  8. from importlib import resources
  9. def get_ths_js(file: str = "ths.js") -> pathlib.Path:
  10. """
  11. get path to data "ths.js" text file.
  12. :return: 文件路径
  13. :rtype: pathlib.Path
  14. """
  15. with resources.path("ak.data", file) as f:
  16. data_file_path = f
  17. return data_file_path
  18. def get_crypto_info_csv(file: str = "crypto_info.zip") -> pathlib.Path:
  19. """
  20. get path to data "ths.js" text file.
  21. :return: 文件路径
  22. :rtype: pathlib.Path
  23. """
  24. with resources.path("ak.data", file) as f:
  25. data_file_path = f
  26. return data_file_path
  27. if __name__ == "__main__":
  28. get_ths_js_path = get_ths_js(file="ths.js")
  29. print(get_ths_js_path)
  30. get_crypto_info_csv_path = get_crypto_info_csv(file="crypto_info.zip")
  31. print(get_crypto_info_csv_path)