本文整理汇总了Python中csv.DictReader.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python DictReader.__init__方法的具体用法?Python DictReader.__init__怎么用?Python DictReader.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类csv.DictReader
的用法示例。
在下文中一共展示了DictReader.__init__方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import __init__ [as 别名]
def __init__(self, fid, commentchar='#', *args, **kwds):
if issubclass(DictReader, object):
super(DictReader, self).__init__(fid, *args, **kwds)
else:
DictReader.__init__(self, fid, *args, **kwds)
self.commentchar = commentchar
self.leadingfield = self.commentchar + 'label'
示例2: __init__
# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import __init__ [as 别名]
def __init__(self,refGene_fn) :
refGene_f = open(refGene_fn)
# check for header
first_line = refGene_f.next()
if not first_line.strip().startswith('#') :
refGene_f.seek(0) # first line not header, reset the file pointer
DictReader.__init__(self,refGene_f,delimiter='\t',fieldnames=RefGeneOutput.FIELD_NAMES)
示例3: __init__
# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import __init__ [as 别名]
def __init__(self, f, fieldnames=None, restkey=None, restval=None,
dialect="excel", *args, **kw):
DictReader.__init__(self, f, fieldnames=fieldnames,
restkey=restkey, restval=restval,
dialect=dialect, *args, **kw)
# Replace the reader with our unicode-enabled reader.
self.reader = UnicodeReader(f, dialect=dialect, *args, **kw)
示例4: __init__
# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import __init__ [as 别名]
def __init__(self, f, fieldnames=None, restkey=None, restval=None,
dialect="excel", encoding='utf-8', *args, **kw):
DictReader.__init__(self, f, fieldnames=fieldnames,
restkey=restkey, restval=restval,
dialect=dialect, *args, **kw)
if not encoding is None:
f = Utf8Recoder(f, encoding=encoding)
# Replace the reader with our unicode-enabled reader.
self.reader = reader(f, dialect=dialect, *args, **kw)
示例5: __init__
# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import __init__ [as 别名]
def __init__(self, f, fieldnames=None, restkey=None, restval=None,
dialect="excel",
encoding=None,
*args, **kwds):
BaseDictReader.__init__(self, f=f, fieldnames=fieldnames,
restkey=restkey, restval=restval,
dialect=dialect,
*args, **kwds)
from .csv import reader
self.reader = reader(f, dialect=dialect,
encoding=encoding,
**kwds)
示例6: __init__
# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import __init__ [as 别名]
def __init__(self, csvfile, fields=None, silent=False, **kwargs):
self.csvfile = csvfile
self.rows_imported = 0
self.errors = []
self.silent = silent
if fields:
if isinstance(fields[0], (list, tuple)):
kwargs['fieldnames'] = [field[0] for field in fields]
self.field_types = dict(fields)
else:
kwargs['fieldnames'] = fields
self.field_types = dict.fromkeys(fields, None)
DictReader.__init__(self, csvfile, **kwargs)
else:
DictReader.__init__(self, csvfile, **kwargs)
self.field_types = dict.fromkeys(self.fieldnames, None)
示例7: __init__
# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import __init__ [as 别名]
def __init__(self, csvfile, casts, fieldnames=None, restkey=None,
restval=None, dialect='excel', *args, **kwds):
"""Arguments:
- f: An iterable object such as as file. Passed on to
csv.DictReader
- casts: A dict mapping from attribute names to functions to apply
to these names, e.g., {'id':int, 'salary':float}
- fieldnames: Passed on to csv.DictReader
- restkey: Passed on to csv.DictReader
- restval: Passed on to csv.DictReader
- dialect: Passed on to csv.DictReader
- *args: Passed on to csv.DictReader
- **kwds: Passed on to csv.DictReader
"""
DictReader.__init__(self, csvfile, fieldnames=fieldnames,
restkey=restkey, restval=restval, dialect=dialect,
*args, **kwds)
if not type(casts) == dict:
raise TypeError("The casts argument must be a dict")
for v in casts.values():
if not callable(v):
raise TypeError("The values in casts must be callable")
self._casts = casts
示例8: __init__
# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import __init__ [as 别名]
def __init__(self, f):
DictReader.__init__(self, f)
self._node = Node(ROOT, [])
self.col_num = 0
self._init()
示例9: __init__
# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import __init__ [as 别名]
def __init__(self, f, fieldnames=None, restkey=None, restval=None,
dialect="excel", encoding="utf-8", *args, **kwargs):
from csv import DictReader
DictReader.__init__(self, f, fieldnames, restkey, restval,
dialect, *args, **kwargs)
self.reader = UnicodeReader(f, dialect, encoding=encoding, *args, **kwargs)
示例10: __init__
# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import __init__ [as 别名]
def __init__(self, *args, **kwargs):
DictReader.__init__(self, *args, **kwargs)
self._fieldnames = map(slugify, self.fieldnames)
示例11: __init__
# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import __init__ [as 别名]
def __init__(self, *args, **kwargs):
args = list(args)
args[0] = utfify(args[0])
DictReader.__init__(self, *args, **kwargs) # DictReader is apparently an old-style class