本文整理汇总了Python中django.core.files.uploadedfile.UploadedFile.readline方法的典型用法代码示例。如果您正苦于以下问题:Python UploadedFile.readline方法的具体用法?Python UploadedFile.readline怎么用?Python UploadedFile.readline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.files.uploadedfile.UploadedFile
的用法示例。
在下文中一共展示了UploadedFile.readline方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: document_validator
# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import readline [as 别名]
def document_validator(filepath, ex_first_row, ex_first_col):
try:
with open(os.path.join(settings.MEDIA_ROOT, filepath), 'r') as f:
file = UploadedFile(f)
dialect = csv.Sniffer().sniff(file.readline(), delimiters=[';', ',', '\t'])
mimetype = magic.from_buffer(file.readline(), mime=True)
file.seek(0)
reader = csv.reader(file, dialect)
temp_list = []
for line in iter(reader):
if reader.line_num == 1:
# save first row
temp_list.append(line)
# save last row
temp_list.append(line)
print ex_first_row
if not ex_first_row:
print "Ciao"
# check char in first row and first col
if not ex_first_row and not float(temp_list[0][-1]):
print 'Hola'
raise ValueError
if not ex_first_col and not float(temp_list[-1][0]):
print 'Hello'
raise ValueError
ncol = (len(temp_list[0]) - 1) if ex_first_col else len(temp_list[0])
nrow = (reader.line_num - 1) if ex_first_col else reader.line_num
if nrow <= 2:
print 'Hey'
raise ValueError
is_cubic = True if (ncol == nrow) else False
return_value = {'is_valid': True, 'nrow': nrow, 'ncol': ncol, 'separator': dialect.delimiter,
'mimetype': mimetype, 'is_cubic': is_cubic}
except csv.Error:
print "Csv"
return_value = {'is_valid': False}
file = None
except Exception:
return_value = {'is_valid': False}
print "Exc"
file = None
except ValueError:
return_value = {'is_valid': False}
print "Value"
file = file
return return_value, file