Skip to content

Instantly share code, notes, and snippets.

@ckunte
Created September 21, 2012 11:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ckunte/3761008 to your computer and use it in GitHub Desktop.
Save ckunte/3761008 to your computer and use it in GitHub Desktop.
Cyrillic (csv or Excel) file to UTF-8 (csv) file converter
#!/usr/bin/env python
# encoding: utf-8
"""
c2u.py
Created by ckunte on 2012-09-21.
Note: Keep the following file be placed in the same folder
as this script file.
Usage (run in Mac Terminal or Gnome Terminal):
$ python c2u.py
"""
import codecs, csv
def main():
# There are two codecs (cp1251, iso8859_5).
# One of the above two should work.
# Comment the line below with # if you use a .xls file.
f = csv.reader('filename.xls', dialect='excel', **fmtparams)
# Comment the line above, and uncomment the line below
# if you use a .csv file.
# f = codecs.open('filename.csv', 'rb', 'iso8859_5')
u = f.read()
o = codecs.open('output.csv', 'w', 'utf-8')
o.write(u)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment