Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Tests some unicode CSV solutions available for Python.
- """
- from __future__ import unicode_literals
- import sys
- TESTS = {
- 'German': [u'Straße', u'auslösen', u'zerstören'],
- 'French': [u'français', u'américaine', u'épais'],
- 'Chinese': [u'中國的', u'英語', u'美國人']
- }
- def perform_test_python2(csv):
- from io import BytesIO
- buffer = BytesIO()
- writer = csv.writer(buffer, encoding='UTF-8')
- writer.writerows([TESTS.keys()])
- for i_row in zip(*TESTS.values()):
- writer.writerows([i_row])
- def perform_test_python3(csv):
- from io import StringIO
- buffer = StringIO()
- writer = csv.writer(buffer)
- writer.writerows([TESTS.keys()])
- for i_row in zip(*TESTS.values()):
- writer.writerows([i_row])
- def perform_test(csv):
- try:
- sys.stdout.write(' Python 2 syntax: ')
- perform_test_python2(csv)
- except Exception as e:
- print(" ERROR")
- else:
- print(" OK")
- try:
- sys.stdout.write(' Python 3 syntax: ')
- perform_test_python3(csv)
- except Exception as e:
- print(" ERROR")
- else:
- print(" OK")
- print("Using csv")
- import csv
- perform_test(csv)
- print("Using unicodecsv")
- import unicodecsv
- perform_test(unicodecsv)
- print("Using csv342")
- import csv342
- perform_test(csv342)
- print("Using csv23")
- import csv23
- perform_test(csv23)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement