Source code for schrodinger.utils.csv_unicode

"""
A wrapper around Python's csv module that allows it to work with Unicode
characters.  (Currently, only the writer class is implemented.)  The interface
is intended to mirror the csv interface.  See Python's csv documentation for an
explanation of methods and method arguments.
"""

import csv
from contextlib import contextmanager

writer = csv.writer


[docs]@contextmanager def reader_open(filename): handle = open(filename, encoding="utf-8", newline="") try: yield handle finally: handle.close()
[docs]@contextmanager def writer_open(filename): handle = open(filename, "w", encoding="utf-8", newline="") try: yield handle finally: handle.close()