gyetvaig

Python get file encoding

Jan 21st, 2019
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. import time
  2.  
  3.  
  4. def get_file_encoding(src_file_path):
  5.     """
  6.    Get the encoding type of a file
  7.    :param src_file_path: file path
  8.    :return: str - file encoding type
  9.    """
  10.     with open(src_file_path) as src_file:
  11.         return src_file.encoding
  12.  
  13.  
  14. file_path = input('Please enter file path: ')
  15. start_time = time.perf_counter()
  16. print(get_file_encoding(file_path))
  17. print('get file encoding: {}'.format(time.perf_counter() - start_time))
Advertisement
Add Comment
Please, Sign In to add comment