Skip to content

Instantly share code, notes, and snippets.

@xbee
Last active August 29, 2015 14:27
Show Gist options
  • Save xbee/35ce7e2f52f88cae6356 to your computer and use it in GitHub Desktop.
Save xbee/35ce7e2f52f88cae6356 to your computer and use it in GitHub Desktop.
A small Python script that converts a file encoded in Code Page 936 (aka GBK) to UTF-8.
#! /usr/bin/env python3.4
# Code Page 936 (GBK) to UTF-8 Transcoder
# Author: Kristian Tang (@Krisiouz)
# A small script that converts a file encoded in Code Page 936 (GBK) to UTF-8.
def gbk_to_utf8(input_file, output_file):
# Load Files
input_file_opened = open(input_file, 'r', encoding='cp936')
input_file_read = input_file_opened.read()
output_file_opened = open(output_file, 'x', encoding='utf-8', newline='\n')
# Transcode
print('Transcoding…')
output_file_opened.write(input_file_read)
input_file_opened.close()
output_file_opened.close()
print('Done.\n')
def main():
print('Code Page 936 (GBK) to UTF-8 Transcoder\n')
# Ask the User Which File to Transcode
while 0 == 0:
input_file = input('Full file path of GBK file:\n')
output_file = input_file + '.utf-8'
gbk_to_utf8(input_file, output_file)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment