def from_csv(cls, file, encoding=None, **fmtparams):
"""Create a DataSource from a CSV *file* (a path or file-like
object)::
source = datatest.DataSource.from_csv('mydata.csv')
If *file* is an iterable of files, data will be loaded and
aligned by column name::
files = ['mydata1.csv', 'mydata2.csv']
source = datatest.DataSource.from_csv(files)
"""
if isinstance(file, string_types) or isinstance(file, IOBase):
file = [file]
new_cls = cls.__new__(cls)
temptable = _from_csv(file, encoding, **fmtparams)
new_cls._connection = temptable.connection
new_cls._table = temptable.name
repr_string = '{0}.from_csv({1}{2}{3})'.format(
new_cls.__class__.__name__,
repr(file[0]) if len(file) == 1 else repr(file),
', {0!r}'.format(encoding) if encoding else '',
', **{0!r}'.format(fmtparams) if fmtparams else '',
)
new_cls._repr_string = repr_string
return new_cls
评论列表
文章目录