读取存储中文件1.py 735 B

123456789101112131415161718
  1. import os
  2. '''
  3. This hacks the python built-in function "open" which add some pre-processing for file operations
  4. to allows the program runs locally and in the Agit environment without modifications.
  5. '''
  6. if 'CLOUD_PROVIDER' in os.environ and os.environ['CLOUD_PROVIDER'] == 'Agit':
  7. from agit import open # override the open function
  8. dataset_path = 'agit://' # data path in the Agit cloud environment
  9. else:
  10. dataset_path = './dataset/' # data path for local running
  11. '''
  12. Agit Datasets only allow read-only mode, the default mode "r" (open for reading text, synonym of "rt")
  13. and "rb " (open for reading binary) are available.
  14. '''
  15. with open(dataset_path + 'datafile.txt', mode='rb', encoding=None) as file:
  16. print(file.read())