gyetvaig icon

Python get file encoding

gyetvaig | PRO | 01/21/19 05:08:26 PM UTC | 0 ⭐ | 384 👁️ | Never ⏰ | []
Python |

450 B

|

None

|

0 👍

/

0 👎

import time
 
 
def get_file_encoding(src_file_path):
    """
    Get the encoding type of a file
    :param src_file_path: file path
    :return: str - file encoding type
    """
    with open(src_file_path) as src_file:
        return src_file.encoding
 
 
file_path = input('Please enter file path: ')
start_time = time.perf_counter()
print(get_file_encoding(file_path))
print('get file encoding: {}'.format(time.perf_counter() - start_time))

Comments