Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2....
File: csv.py
[0] Fix | Delete
"""
[1] Fix | Delete
csv.py - read/write/investigate CSV files
[2] Fix | Delete
"""
[3] Fix | Delete
[4] Fix | Delete
import re
[5] Fix | Delete
from functools import reduce
[6] Fix | Delete
from _csv import Error, __version__, writer, reader, register_dialect, \
[7] Fix | Delete
unregister_dialect, get_dialect, list_dialects, \
[8] Fix | Delete
field_size_limit, \
[9] Fix | Delete
QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC, QUOTE_NONE, \
[10] Fix | Delete
__doc__
[11] Fix | Delete
from _csv import Dialect as _Dialect
[12] Fix | Delete
[13] Fix | Delete
try:
[14] Fix | Delete
from cStringIO import StringIO
[15] Fix | Delete
except ImportError:
[16] Fix | Delete
from StringIO import StringIO
[17] Fix | Delete
[18] Fix | Delete
__all__ = [ "QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
[19] Fix | Delete
"Error", "Dialect", "__doc__", "excel", "excel_tab",
[20] Fix | Delete
"field_size_limit", "reader", "writer",
[21] Fix | Delete
"register_dialect", "get_dialect", "list_dialects", "Sniffer",
[22] Fix | Delete
"unregister_dialect", "__version__", "DictReader", "DictWriter" ]
[23] Fix | Delete
[24] Fix | Delete
class Dialect:
[25] Fix | Delete
"""Describe an Excel dialect.
[26] Fix | Delete
[27] Fix | Delete
This must be subclassed (see csv.excel). Valid attributes are:
[28] Fix | Delete
delimiter, quotechar, escapechar, doublequote, skipinitialspace,
[29] Fix | Delete
lineterminator, quoting.
[30] Fix | Delete
[31] Fix | Delete
"""
[32] Fix | Delete
_name = ""
[33] Fix | Delete
_valid = False
[34] Fix | Delete
# placeholders
[35] Fix | Delete
delimiter = None
[36] Fix | Delete
quotechar = None
[37] Fix | Delete
escapechar = None
[38] Fix | Delete
doublequote = None
[39] Fix | Delete
skipinitialspace = None
[40] Fix | Delete
lineterminator = None
[41] Fix | Delete
quoting = None
[42] Fix | Delete
[43] Fix | Delete
def __init__(self):
[44] Fix | Delete
if self.__class__ != Dialect:
[45] Fix | Delete
self._valid = True
[46] Fix | Delete
self._validate()
[47] Fix | Delete
[48] Fix | Delete
def _validate(self):
[49] Fix | Delete
try:
[50] Fix | Delete
_Dialect(self)
[51] Fix | Delete
except TypeError, e:
[52] Fix | Delete
# We do this for compatibility with py2.3
[53] Fix | Delete
raise Error(str(e))
[54] Fix | Delete
[55] Fix | Delete
class excel(Dialect):
[56] Fix | Delete
"""Describe the usual properties of Excel-generated CSV files."""
[57] Fix | Delete
delimiter = ','
[58] Fix | Delete
quotechar = '"'
[59] Fix | Delete
doublequote = True
[60] Fix | Delete
skipinitialspace = False
[61] Fix | Delete
lineterminator = '\r\n'
[62] Fix | Delete
quoting = QUOTE_MINIMAL
[63] Fix | Delete
register_dialect("excel", excel)
[64] Fix | Delete
[65] Fix | Delete
class excel_tab(excel):
[66] Fix | Delete
"""Describe the usual properties of Excel-generated TAB-delimited files."""
[67] Fix | Delete
delimiter = '\t'
[68] Fix | Delete
register_dialect("excel-tab", excel_tab)
[69] Fix | Delete
[70] Fix | Delete
[71] Fix | Delete
class DictReader:
[72] Fix | Delete
def __init__(self, f, fieldnames=None, restkey=None, restval=None,
[73] Fix | Delete
dialect="excel", *args, **kwds):
[74] Fix | Delete
self._fieldnames = fieldnames # list of keys for the dict
[75] Fix | Delete
self.restkey = restkey # key to catch long rows
[76] Fix | Delete
self.restval = restval # default value for short rows
[77] Fix | Delete
self.reader = reader(f, dialect, *args, **kwds)
[78] Fix | Delete
self.dialect = dialect
[79] Fix | Delete
self.line_num = 0
[80] Fix | Delete
[81] Fix | Delete
def __iter__(self):
[82] Fix | Delete
return self
[83] Fix | Delete
[84] Fix | Delete
@property
[85] Fix | Delete
def fieldnames(self):
[86] Fix | Delete
if self._fieldnames is None:
[87] Fix | Delete
try:
[88] Fix | Delete
self._fieldnames = self.reader.next()
[89] Fix | Delete
except StopIteration:
[90] Fix | Delete
pass
[91] Fix | Delete
self.line_num = self.reader.line_num
[92] Fix | Delete
return self._fieldnames
[93] Fix | Delete
[94] Fix | Delete
# Issue 20004: Because DictReader is a classic class, this setter is
[95] Fix | Delete
# ignored. At this point in 2.7's lifecycle, it is too late to change the
[96] Fix | Delete
# base class for fear of breaking working code. If you want to change
[97] Fix | Delete
# fieldnames without overwriting the getter, set _fieldnames directly.
[98] Fix | Delete
@fieldnames.setter
[99] Fix | Delete
def fieldnames(self, value):
[100] Fix | Delete
self._fieldnames = value
[101] Fix | Delete
[102] Fix | Delete
def next(self):
[103] Fix | Delete
if self.line_num == 0:
[104] Fix | Delete
# Used only for its side effect.
[105] Fix | Delete
self.fieldnames
[106] Fix | Delete
row = self.reader.next()
[107] Fix | Delete
self.line_num = self.reader.line_num
[108] Fix | Delete
[109] Fix | Delete
# unlike the basic reader, we prefer not to return blanks,
[110] Fix | Delete
# because we will typically wind up with a dict full of None
[111] Fix | Delete
# values
[112] Fix | Delete
while row == []:
[113] Fix | Delete
row = self.reader.next()
[114] Fix | Delete
d = dict(zip(self.fieldnames, row))
[115] Fix | Delete
lf = len(self.fieldnames)
[116] Fix | Delete
lr = len(row)
[117] Fix | Delete
if lf < lr:
[118] Fix | Delete
d[self.restkey] = row[lf:]
[119] Fix | Delete
elif lf > lr:
[120] Fix | Delete
for key in self.fieldnames[lr:]:
[121] Fix | Delete
d[key] = self.restval
[122] Fix | Delete
return d
[123] Fix | Delete
[124] Fix | Delete
[125] Fix | Delete
class DictWriter:
[126] Fix | Delete
def __init__(self, f, fieldnames, restval="", extrasaction="raise",
[127] Fix | Delete
dialect="excel", *args, **kwds):
[128] Fix | Delete
self.fieldnames = fieldnames # list of keys for the dict
[129] Fix | Delete
self.restval = restval # for writing short dicts
[130] Fix | Delete
if extrasaction.lower() not in ("raise", "ignore"):
[131] Fix | Delete
raise ValueError, \
[132] Fix | Delete
("extrasaction (%s) must be 'raise' or 'ignore'" %
[133] Fix | Delete
extrasaction)
[134] Fix | Delete
self.extrasaction = extrasaction
[135] Fix | Delete
self.writer = writer(f, dialect, *args, **kwds)
[136] Fix | Delete
[137] Fix | Delete
def writeheader(self):
[138] Fix | Delete
header = dict(zip(self.fieldnames, self.fieldnames))
[139] Fix | Delete
self.writerow(header)
[140] Fix | Delete
[141] Fix | Delete
def _dict_to_list(self, rowdict):
[142] Fix | Delete
if self.extrasaction == "raise":
[143] Fix | Delete
wrong_fields = [k for k in rowdict if k not in self.fieldnames]
[144] Fix | Delete
if wrong_fields:
[145] Fix | Delete
raise ValueError("dict contains fields not in fieldnames: "
[146] Fix | Delete
+ ", ".join([repr(x) for x in wrong_fields]))
[147] Fix | Delete
return [rowdict.get(key, self.restval) for key in self.fieldnames]
[148] Fix | Delete
[149] Fix | Delete
def writerow(self, rowdict):
[150] Fix | Delete
return self.writer.writerow(self._dict_to_list(rowdict))
[151] Fix | Delete
[152] Fix | Delete
def writerows(self, rowdicts):
[153] Fix | Delete
rows = []
[154] Fix | Delete
for rowdict in rowdicts:
[155] Fix | Delete
rows.append(self._dict_to_list(rowdict))
[156] Fix | Delete
return self.writer.writerows(rows)
[157] Fix | Delete
[158] Fix | Delete
# Guard Sniffer's type checking against builds that exclude complex()
[159] Fix | Delete
try:
[160] Fix | Delete
complex
[161] Fix | Delete
except NameError:
[162] Fix | Delete
complex = float
[163] Fix | Delete
[164] Fix | Delete
class Sniffer:
[165] Fix | Delete
'''
[166] Fix | Delete
"Sniffs" the format of a CSV file (i.e. delimiter, quotechar)
[167] Fix | Delete
Returns a Dialect object.
[168] Fix | Delete
'''
[169] Fix | Delete
def __init__(self):
[170] Fix | Delete
# in case there is more than one possible delimiter
[171] Fix | Delete
self.preferred = [',', '\t', ';', ' ', ':']
[172] Fix | Delete
[173] Fix | Delete
[174] Fix | Delete
def sniff(self, sample, delimiters=None):
[175] Fix | Delete
"""
[176] Fix | Delete
Returns a dialect (or None) corresponding to the sample
[177] Fix | Delete
"""
[178] Fix | Delete
[179] Fix | Delete
quotechar, doublequote, delimiter, skipinitialspace = \
[180] Fix | Delete
self._guess_quote_and_delimiter(sample, delimiters)
[181] Fix | Delete
if not delimiter:
[182] Fix | Delete
delimiter, skipinitialspace = self._guess_delimiter(sample,
[183] Fix | Delete
delimiters)
[184] Fix | Delete
[185] Fix | Delete
if not delimiter:
[186] Fix | Delete
raise Error, "Could not determine delimiter"
[187] Fix | Delete
[188] Fix | Delete
class dialect(Dialect):
[189] Fix | Delete
_name = "sniffed"
[190] Fix | Delete
lineterminator = '\r\n'
[191] Fix | Delete
quoting = QUOTE_MINIMAL
[192] Fix | Delete
# escapechar = ''
[193] Fix | Delete
[194] Fix | Delete
dialect.doublequote = doublequote
[195] Fix | Delete
dialect.delimiter = delimiter
[196] Fix | Delete
# _csv.reader won't accept a quotechar of ''
[197] Fix | Delete
dialect.quotechar = quotechar or '"'
[198] Fix | Delete
dialect.skipinitialspace = skipinitialspace
[199] Fix | Delete
[200] Fix | Delete
return dialect
[201] Fix | Delete
[202] Fix | Delete
[203] Fix | Delete
def _guess_quote_and_delimiter(self, data, delimiters):
[204] Fix | Delete
"""
[205] Fix | Delete
Looks for text enclosed between two identical quotes
[206] Fix | Delete
(the probable quotechar) which are preceded and followed
[207] Fix | Delete
by the same character (the probable delimiter).
[208] Fix | Delete
For example:
[209] Fix | Delete
,'some text',
[210] Fix | Delete
The quote with the most wins, same with the delimiter.
[211] Fix | Delete
If there is no quotechar the delimiter can't be determined
[212] Fix | Delete
this way.
[213] Fix | Delete
"""
[214] Fix | Delete
[215] Fix | Delete
matches = []
[216] Fix | Delete
for restr in ('(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
[217] Fix | Delete
'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?",
[218] Fix | Delete
'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?"
[219] Fix | Delete
'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space)
[220] Fix | Delete
regexp = re.compile(restr, re.DOTALL | re.MULTILINE)
[221] Fix | Delete
matches = regexp.findall(data)
[222] Fix | Delete
if matches:
[223] Fix | Delete
break
[224] Fix | Delete
[225] Fix | Delete
if not matches:
[226] Fix | Delete
# (quotechar, doublequote, delimiter, skipinitialspace)
[227] Fix | Delete
return ('', False, None, 0)
[228] Fix | Delete
quotes = {}
[229] Fix | Delete
delims = {}
[230] Fix | Delete
spaces = 0
[231] Fix | Delete
for m in matches:
[232] Fix | Delete
n = regexp.groupindex['quote'] - 1
[233] Fix | Delete
key = m[n]
[234] Fix | Delete
if key:
[235] Fix | Delete
quotes[key] = quotes.get(key, 0) + 1
[236] Fix | Delete
try:
[237] Fix | Delete
n = regexp.groupindex['delim'] - 1
[238] Fix | Delete
key = m[n]
[239] Fix | Delete
except KeyError:
[240] Fix | Delete
continue
[241] Fix | Delete
if key and (delimiters is None or key in delimiters):
[242] Fix | Delete
delims[key] = delims.get(key, 0) + 1
[243] Fix | Delete
try:
[244] Fix | Delete
n = regexp.groupindex['space'] - 1
[245] Fix | Delete
except KeyError:
[246] Fix | Delete
continue
[247] Fix | Delete
if m[n]:
[248] Fix | Delete
spaces += 1
[249] Fix | Delete
[250] Fix | Delete
quotechar = reduce(lambda a, b, quotes = quotes:
[251] Fix | Delete
(quotes[a] > quotes[b]) and a or b, quotes.keys())
[252] Fix | Delete
[253] Fix | Delete
if delims:
[254] Fix | Delete
delim = reduce(lambda a, b, delims = delims:
[255] Fix | Delete
(delims[a] > delims[b]) and a or b, delims.keys())
[256] Fix | Delete
skipinitialspace = delims[delim] == spaces
[257] Fix | Delete
if delim == '\n': # most likely a file with a single column
[258] Fix | Delete
delim = ''
[259] Fix | Delete
else:
[260] Fix | Delete
# there is *no* delimiter, it's a single column of quoted data
[261] Fix | Delete
delim = ''
[262] Fix | Delete
skipinitialspace = 0
[263] Fix | Delete
[264] Fix | Delete
# if we see an extra quote between delimiters, we've got a
[265] Fix | Delete
# double quoted format
[266] Fix | Delete
dq_regexp = re.compile(
[267] Fix | Delete
r"((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)" % \
[268] Fix | Delete
{'delim':re.escape(delim), 'quote':quotechar}, re.MULTILINE)
[269] Fix | Delete
[270] Fix | Delete
[271] Fix | Delete
[272] Fix | Delete
if dq_regexp.search(data):
[273] Fix | Delete
doublequote = True
[274] Fix | Delete
else:
[275] Fix | Delete
doublequote = False
[276] Fix | Delete
[277] Fix | Delete
return (quotechar, doublequote, delim, skipinitialspace)
[278] Fix | Delete
[279] Fix | Delete
[280] Fix | Delete
def _guess_delimiter(self, data, delimiters):
[281] Fix | Delete
"""
[282] Fix | Delete
The delimiter /should/ occur the same number of times on
[283] Fix | Delete
each row. However, due to malformed data, it may not. We don't want
[284] Fix | Delete
an all or nothing approach, so we allow for small variations in this
[285] Fix | Delete
number.
[286] Fix | Delete
1) build a table of the frequency of each character on every line.
[287] Fix | Delete
2) build a table of frequencies of this frequency (meta-frequency?),
[288] Fix | Delete
e.g. 'x occurred 5 times in 10 rows, 6 times in 1000 rows,
[289] Fix | Delete
7 times in 2 rows'
[290] Fix | Delete
3) use the mode of the meta-frequency to determine the /expected/
[291] Fix | Delete
frequency for that character
[292] Fix | Delete
4) find out how often the character actually meets that goal
[293] Fix | Delete
5) the character that best meets its goal is the delimiter
[294] Fix | Delete
For performance reasons, the data is evaluated in chunks, so it can
[295] Fix | Delete
try and evaluate the smallest portion of the data possible, evaluating
[296] Fix | Delete
additional chunks as necessary.
[297] Fix | Delete
"""
[298] Fix | Delete
[299] Fix | Delete
data = filter(None, data.split('\n'))
[300] Fix | Delete
[301] Fix | Delete
ascii = [chr(c) for c in range(127)] # 7-bit ASCII
[302] Fix | Delete
[303] Fix | Delete
# build frequency tables
[304] Fix | Delete
chunkLength = min(10, len(data))
[305] Fix | Delete
iteration = 0
[306] Fix | Delete
charFrequency = {}
[307] Fix | Delete
modes = {}
[308] Fix | Delete
delims = {}
[309] Fix | Delete
start, end = 0, min(chunkLength, len(data))
[310] Fix | Delete
while start < len(data):
[311] Fix | Delete
iteration += 1
[312] Fix | Delete
for line in data[start:end]:
[313] Fix | Delete
for char in ascii:
[314] Fix | Delete
metaFrequency = charFrequency.get(char, {})
[315] Fix | Delete
# must count even if frequency is 0
[316] Fix | Delete
freq = line.count(char)
[317] Fix | Delete
# value is the mode
[318] Fix | Delete
metaFrequency[freq] = metaFrequency.get(freq, 0) + 1
[319] Fix | Delete
charFrequency[char] = metaFrequency
[320] Fix | Delete
[321] Fix | Delete
for char in charFrequency.keys():
[322] Fix | Delete
items = charFrequency[char].items()
[323] Fix | Delete
if len(items) == 1 and items[0][0] == 0:
[324] Fix | Delete
continue
[325] Fix | Delete
# get the mode of the frequencies
[326] Fix | Delete
if len(items) > 1:
[327] Fix | Delete
modes[char] = reduce(lambda a, b: a[1] > b[1] and a or b,
[328] Fix | Delete
items)
[329] Fix | Delete
# adjust the mode - subtract the sum of all
[330] Fix | Delete
# other frequencies
[331] Fix | Delete
items.remove(modes[char])
[332] Fix | Delete
modes[char] = (modes[char][0], modes[char][1]
[333] Fix | Delete
- reduce(lambda a, b: (0, a[1] + b[1]),
[334] Fix | Delete
items)[1])
[335] Fix | Delete
else:
[336] Fix | Delete
modes[char] = items[0]
[337] Fix | Delete
[338] Fix | Delete
# build a list of possible delimiters
[339] Fix | Delete
modeList = modes.items()
[340] Fix | Delete
total = float(chunkLength * iteration)
[341] Fix | Delete
# (rows of consistent data) / (number of rows) = 100%
[342] Fix | Delete
consistency = 1.0
[343] Fix | Delete
# minimum consistency threshold
[344] Fix | Delete
threshold = 0.9
[345] Fix | Delete
while len(delims) == 0 and consistency >= threshold:
[346] Fix | Delete
for k, v in modeList:
[347] Fix | Delete
if v[0] > 0 and v[1] > 0:
[348] Fix | Delete
if ((v[1]/total) >= consistency and
[349] Fix | Delete
(delimiters is None or k in delimiters)):
[350] Fix | Delete
delims[k] = v
[351] Fix | Delete
consistency -= 0.01
[352] Fix | Delete
[353] Fix | Delete
if len(delims) == 1:
[354] Fix | Delete
delim = delims.keys()[0]
[355] Fix | Delete
skipinitialspace = (data[0].count(delim) ==
[356] Fix | Delete
data[0].count("%c " % delim))
[357] Fix | Delete
return (delim, skipinitialspace)
[358] Fix | Delete
[359] Fix | Delete
# analyze another chunkLength lines
[360] Fix | Delete
start = end
[361] Fix | Delete
end += chunkLength
[362] Fix | Delete
[363] Fix | Delete
if not delims:
[364] Fix | Delete
return ('', 0)
[365] Fix | Delete
[366] Fix | Delete
# if there's more than one, fall back to a 'preferred' list
[367] Fix | Delete
if len(delims) > 1:
[368] Fix | Delete
for d in self.preferred:
[369] Fix | Delete
if d in delims.keys():
[370] Fix | Delete
skipinitialspace = (data[0].count(d) ==
[371] Fix | Delete
data[0].count("%c " % d))
[372] Fix | Delete
return (d, skipinitialspace)
[373] Fix | Delete
[374] Fix | Delete
# nothing else indicates a preference, pick the character that
[375] Fix | Delete
# dominates(?)
[376] Fix | Delete
items = [(v,k) for (k,v) in delims.items()]
[377] Fix | Delete
items.sort()
[378] Fix | Delete
delim = items[-1][1]
[379] Fix | Delete
[380] Fix | Delete
skipinitialspace = (data[0].count(delim) ==
[381] Fix | Delete
data[0].count("%c " % delim))
[382] Fix | Delete
return (delim, skipinitialspace)
[383] Fix | Delete
[384] Fix | Delete
[385] Fix | Delete
def has_header(self, sample):
[386] Fix | Delete
# Creates a dictionary of types of data in each column. If any
[387] Fix | Delete
# column is of a single type (say, integers), *except* for the first
[388] Fix | Delete
# row, then the first row is presumed to be labels. If the type
[389] Fix | Delete
# can't be determined, it is assumed to be a string in which case
[390] Fix | Delete
# the length of the string is the determining factor: if all of the
[391] Fix | Delete
# rows except for the first are the same length, it's a header.
[392] Fix | Delete
# Finally, a 'vote' is taken at the end for each column, adding or
[393] Fix | Delete
# subtracting from the likelihood of the first row being a header.
[394] Fix | Delete
[395] Fix | Delete
rdr = reader(StringIO(sample), self.sniff(sample))
[396] Fix | Delete
[397] Fix | Delete
header = rdr.next() # assume first row is header
[398] Fix | Delete
[399] Fix | Delete
columns = len(header)
[400] Fix | Delete
columnTypes = {}
[401] Fix | Delete
for i in range(columns): columnTypes[i] = None
[402] Fix | Delete
[403] Fix | Delete
checked = 0
[404] Fix | Delete
for row in rdr:
[405] Fix | Delete
# arbitrary number of rows to check, to keep it sane
[406] Fix | Delete
if checked > 20:
[407] Fix | Delete
break
[408] Fix | Delete
checked += 1
[409] Fix | Delete
[410] Fix | Delete
if len(row) != columns:
[411] Fix | Delete
continue # skip rows that have irregular number of columns
[412] Fix | Delete
[413] Fix | Delete
for col in columnTypes.keys():
[414] Fix | Delete
[415] Fix | Delete
for thisType in [int, long, float, complex]:
[416] Fix | Delete
try:
[417] Fix | Delete
thisType(row[col])
[418] Fix | Delete
break
[419] Fix | Delete
except (ValueError, OverflowError):
[420] Fix | Delete
pass
[421] Fix | Delete
else:
[422] Fix | Delete
# fallback to length of string
[423] Fix | Delete
thisType = len(row[col])
[424] Fix | Delete
[425] Fix | Delete
# treat longs as ints
[426] Fix | Delete
if thisType == long:
[427] Fix | Delete
thisType = int
[428] Fix | Delete
[429] Fix | Delete
if thisType != columnTypes[col]:
[430] Fix | Delete
if columnTypes[col] is None: # add new column type
[431] Fix | Delete
columnTypes[col] = thisType
[432] Fix | Delete
else:
[433] Fix | Delete
# type is inconsistent, remove column from
[434] Fix | Delete
# consideration
[435] Fix | Delete
del columnTypes[col]
[436] Fix | Delete
[437] Fix | Delete
# finally, compare results against first row and "vote"
[438] Fix | Delete
# on whether it's a header
[439] Fix | Delete
hasHeader = 0
[440] Fix | Delete
for col, colType in columnTypes.items():
[441] Fix | Delete
if type(colType) == type(0): # it's a length
[442] Fix | Delete
if len(header[col]) != colType:
[443] Fix | Delete
hasHeader += 1
[444] Fix | Delete
else:
[445] Fix | Delete
hasHeader -= 1
[446] Fix | Delete
else: # attempt typecast
[447] Fix | Delete
try:
[448] Fix | Delete
colType(header[col])
[449] Fix | Delete
except (ValueError, TypeError):
[450] Fix | Delete
hasHeader += 1
[451] Fix | Delete
else:
[452] Fix | Delete
hasHeader -= 1
[453] Fix | Delete
[454] Fix | Delete
return hasHeader > 0
[455] Fix | Delete
[456] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function