本文整理汇总了Python中csv.QUOTE_MINIMAL属性的典型用法代码示例。如果您正苦于以下问题:Python csv.QUOTE_MINIMAL属性的具体用法?Python csv.QUOTE_MINIMAL怎么用?Python csv.QUOTE_MINIMAL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类csv
的用法示例。
在下文中一共展示了csv.QUOTE_MINIMAL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def handle(self, *args, **options):
documents = Document.objects.filter(verified=True)
with open('docs_with_several_verified_entries.csv', 'wb') as csvfile:
impwriter = csv.writer(csvfile, delimiter=',',
quotechar='"', quoting=csv.QUOTE_MINIMAL)
# report on documents validated more than once
for doc in documents:
form_entries = doc.form_entries.all()
form_fields = doc.document_set.form.all()[0].fields.filter(verify=True)
if len(form_entries) > 2:
verified_entry_count = 0
for fe in form_entries:
fe_to_dict = fe.to_dict()
#print "-------- For entry user %s." % fe_to_dict['username']
if fe_to_dict['answer_Adjudicatario_verified'] or \
fe_to_dict['answer_Tipo de gasto_verified'] or \
fe_to_dict['answer_Importe total_verified']:
verified_entry_count += 1
if verified_entry_count > 1:
print "The doc %s has more than one entry verified." % doc.id
doc.unverify()
doc.verify()
impwriter.writerow([doc.id, doc.verified])
示例2: success_csv
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def success_csv(self, url, rurl, port, IP, statuscode):
if options().csvfile:
if not options().csvfile.endswith(".csv"):
csvfile = f"{options().csvfile}.csv"
else:
csvfile = options().csvfile
if os.path.isfile(csvfile):
pass
else:
with open(csvfile, "w") as csvf:
writer = csv.writer(csvf, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(["URL", "REDIRECT", "PORT", "IP", "STATUS CODE"])
with open(csvfile, "a") as csvf:
writer = csv.writer(csvf, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow([url, rurl, port, IP, statuscode])
示例3: _convert_xpt_to_csv
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def _convert_xpt_to_csv(self):
if not os.path.exists(self._csv_path):
os.mkdir(self._csv_path)
for i in range(len(self._cdcfiles)):
f = self._cdcfiles[i]
finfo = self._cdcfileinfo[i]
xptfile = os.path.join(self._dirpath, f)
csvfile = os.path.join(self._csv_path, f)
csvfile = os.path.splitext(csvfile)[0]
csvfile = csvfile + ".csv"
if not os.path.exists(csvfile):
print("converting ", finfo, ": ", xptfile, " to ", csvfile)
with open(xptfile, 'rb') as in_xpt:
with open(csvfile, 'w',newline='') as out_csv:
reader = xport.Reader(in_xpt)
writer = csv.writer(out_csv, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(reader.fields)
for row in reader:
writer.writerow(row)
示例4: _test_default_attrs
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def _test_default_attrs(self, ctor, *args):
obj = ctor(*args)
# Check defaults
self.assertEqual(obj.dialect.delimiter, ',')
self.assertEqual(obj.dialect.doublequote, True)
self.assertEqual(obj.dialect.escapechar, None)
self.assertEqual(obj.dialect.lineterminator, "\r\n")
self.assertEqual(obj.dialect.quotechar, '"')
self.assertEqual(obj.dialect.quoting, csv.QUOTE_MINIMAL)
self.assertEqual(obj.dialect.skipinitialspace, False)
self.assertEqual(obj.dialect.strict, False)
# Try deleting or changing attributes (they are read-only)
self.assertRaises(TypeError, delattr, obj.dialect, 'delimiter')
self.assertRaises(TypeError, setattr, obj.dialect, 'delimiter', ':')
self.assertRaises(AttributeError, delattr, obj.dialect, 'quoting')
self.assertRaises(AttributeError, setattr, obj.dialect,
'quoting', None)
示例5: test_write_escape
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def test_write_escape(self):
self._write_test(['a',1,'p,q'], 'a,1,"p,q"',
escapechar='\\')
self._write_error_test(csv.Error, ['a',1,'p,"q"'],
escapechar=None, doublequote=False)
self._write_test(['a',1,'p,"q"'], 'a,1,"p,\\"q\\""',
escapechar='\\', doublequote = False)
self._write_test(['"'], '""""',
escapechar='\\', quoting = csv.QUOTE_MINIMAL)
self._write_test(['"'], '\\"',
escapechar='\\', quoting = csv.QUOTE_MINIMAL,
doublequote = False)
self._write_test(['"'], '\\"',
escapechar='\\', quoting = csv.QUOTE_NONE)
self._write_test(['a',1,'p,q'], 'a,1,p\\,q',
escapechar='\\', quoting = csv.QUOTE_NONE)
示例6: test_bad_quote_char
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def test_bad_quote_char(self):
data = '1,2,3'
# Python 2.x: "...must be an 1-character..."
# Python 3.x: "...must be a 1-character..."
msg = '"quotechar" must be a(n)? 1-character string'
tm.assert_raises_regex(TypeError, msg, self.read_csv,
StringIO(data), quotechar='foo')
msg = 'quotechar must be set if quoting enabled'
tm.assert_raises_regex(TypeError, msg, self.read_csv,
StringIO(data), quotechar=None,
quoting=csv.QUOTE_MINIMAL)
msg = '"quotechar" must be string, not int'
tm.assert_raises_regex(TypeError, msg, self.read_csv,
StringIO(data), quotechar=2)
示例7: test_null_quote_char
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def test_null_quote_char(self):
data = 'a,b,c\n1,2,3'
# sanity checks
msg = 'quotechar must be set if quoting enabled'
tm.assert_raises_regex(TypeError, msg, self.read_csv,
StringIO(data), quotechar=None,
quoting=csv.QUOTE_MINIMAL)
tm.assert_raises_regex(TypeError, msg, self.read_csv,
StringIO(data), quotechar='',
quoting=csv.QUOTE_MINIMAL)
# no errors should be raised if quoting is None
expected = DataFrame([[1, 2, 3]],
columns=['a', 'b', 'c'])
result = self.read_csv(StringIO(data), quotechar=None,
quoting=csv.QUOTE_NONE)
tm.assert_frame_equal(result, expected)
result = self.read_csv(StringIO(data), quotechar='',
quoting=csv.QUOTE_NONE)
tm.assert_frame_equal(result, expected)
示例8: test_write_escape
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def test_write_escape(self):
self._write_test(['a',1,'p,q'], 'a,1,"p,q"',
escapechar='\\')
self.assertRaises(csv.Error,
self._write_test,
['a',1,'p,"q"'], 'a,1,"p,\\"q\\""',
escapechar=None, doublequote=False)
self._write_test(['a',1,'p,"q"'], 'a,1,"p,\\"q\\""',
escapechar='\\', doublequote = False)
self._write_test(['"'], '""""',
escapechar='\\', quoting = csv.QUOTE_MINIMAL)
self._write_test(['"'], '\\"',
escapechar='\\', quoting = csv.QUOTE_MINIMAL,
doublequote = False)
self._write_test(['"'], '\\"',
escapechar='\\', quoting = csv.QUOTE_NONE)
self._write_test(['a',1,'p,q'], 'a,1,p\\,q',
escapechar='\\', quoting = csv.QUOTE_NONE)
示例9: create_csv_file
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def create_csv_file(data_root, output_file, fields):
"""
create a csv file to store the paths of files for each patient
"""
filenames = []
patient_names = os.listdir(data_root + '/' + fields[0])
print(len(patient_names))
for patient_name in patient_names:
patient_image_names = []
for field in fields:
image_name = data_root + '/' + field + '/' + patient_name
image_name = image_name[len(data_root) + 1 :]
patient_image_names.append(image_name)
filenames.append(patient_image_names)
with open(output_file, mode='w') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=',',
quotechar='"',quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(fields)
for item in filenames:
csv_writer.writerow(item)
示例10: create_csv_file
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def create_csv_file(data_root, output_file, fields):
"""
create a csv file to store the paths of files for each patient
"""
filenames = []
patient_names = os.listdir(data_root + '/' + fields[1])
patient_names.sort()
print('total number of images {0:}'.format(len(patient_names)))
for patient_name in patient_names:
patient_image_names = []
for field in fields:
image_name = field + '/' + patient_name
# if(field == 'image'):
# image_name = image_name.replace('_seg.', '.')
# #image_name = image_name[:-4]
patient_image_names.append(image_name)
filenames.append(patient_image_names)
with open(output_file, mode='w') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=',',
quotechar='"',quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(fields)
for item in filenames:
csv_writer.writerow(item)
示例11: create_csv_file
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def create_csv_file(data_root, output_file):
"""
create a csv file to store the paths of files for each patient
"""
image_folder = data_root + "/" + "training_set"
label_folder = data_root + "/" + "training_set_label"
filenames = os.listdir(label_folder)
filenames = [item for item in filenames if item[0] != '.']
file_list = []
for filename in filenames:
image_name = "training_set" + "/" + filename.replace("_seg.", ".")
label_name = "training_set_label" + "/" + filename
file_list.append([image_name, label_name])
with open(output_file, mode='w') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=',',
quotechar='"',quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(["image", "label"])
for item in file_list:
csv_writer.writerow(item)
示例12: output
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def output(self):
with open(RunParameters.OUTPUT_FILE, "a") as csv_file:
writer = csv.writer(csv_file, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
while (time.time() - self.start_time) < self.time_limit:
#computing snapshots
num_snapshots = 0
for key in self.state_graph.states:
if self.state_graph.states[key].solid:
num_snapshots = num_snapshots+1
#read coverage
coverage_manager.pull_coverage_files("temp")
coverage_manager.compute_current_coverage() # output in coverage.txt
current_coverage = coverage_manager.read_current_coverage()
# write files
writer.writerow([str(int(time.time()-self.start_time)), str(len(self.state_graph.states)),str(num_snapshots), str(self.num_restore), str(current_coverage)])
time.sleep(120)
print "current threads: " + str(threading.active_count())
csv_file.close()
示例13: dump_results_to_csv
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def dump_results_to_csv(final_result, result_steps, decimal_precision, error_minimo):
FILE_PATH = 'aproximation_result.csv'
solution_len = len(final_result)
with open(FILE_PATH, mode='w') as f:
csv_writer = csv.writer(
f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL
)
coordinates = [f'X_{i}' for i in range(solution_len)]
csv_writer.writerow(
['i'] + coordinates + ['Norma 1', 'Norma 2', 'Norma 3', 'Criterio de Paro']
)
for i, step in enumerate(result_steps):
array_elems = [round(number, decimal_precision) for number in step[0]]
normas = [
round(norma, decimal_precision) if norma != '-' else '-'
for norma in step[1:]
]
row = [i] + array_elems + normas + [error_minimo]
csv_writer.writerow(row)
return FILE_PATH
示例14: _test_default_attrs
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def _test_default_attrs(self, ctor, *args):
obj = ctor(*args)
# Check defaults
self.assertEqual(obj.dialect.delimiter, ',')
self.assertEqual(obj.dialect.doublequote, True)
self.assertEqual(obj.dialect.escapechar, None)
self.assertEqual(obj.dialect.lineterminator, "\r\n")
self.assertEqual(obj.dialect.quotechar, '"')
self.assertEqual(obj.dialect.quoting, csv.QUOTE_MINIMAL)
self.assertEqual(obj.dialect.skipinitialspace, False)
self.assertEqual(obj.dialect.strict, False)
# Try deleting or changing attributes (they are read-only)
self.assertRaises(AttributeError, delattr, obj.dialect, 'delimiter')
self.assertRaises(AttributeError, setattr, obj.dialect, 'delimiter', ':')
self.assertRaises(AttributeError, delattr, obj.dialect, 'quoting')
self.assertRaises(AttributeError, setattr, obj.dialect,
'quoting', None)
示例15: write_csv
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_MINIMAL [as 别名]
def write_csv(
filename: str,
data: Union[List, np.ndarray],
column_names: Optional[List[str]] = None,
):
"""Write a csv file.
Parameters
----------
filename : str
Filename for saving csv.
data : list or ndarray
Table values, contained in a list of lists or an ndarray.
column_names : list, optional
List of column names for table data.
"""
with open(filename, mode='w', newline='') as csvfile:
writer = csv.writer(
csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL,
)
if column_names is not None:
writer.writerow(column_names)
for row in data:
writer.writerow(row)