本文整理汇总了Python中unicodecsv.QUOTE_ALL属性的典型用法代码示例。如果您正苦于以下问题:Python unicodecsv.QUOTE_ALL属性的具体用法?Python unicodecsv.QUOTE_ALL怎么用?Python unicodecsv.QUOTE_ALL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类unicodecsv
的用法示例。
在下文中一共展示了unicodecsv.QUOTE_ALL属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_arg_valid
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_ALL [as 别名]
def _test_arg_valid(self, ctor, arg):
self.assertRaises(py_compat_exc, ctor)
self.assertRaises(py_compat_exc, ctor, None)
self.assertRaises(py_compat_exc, ctor, arg, bad_attr=0)
self.assertRaises(py_compat_exc, ctor, arg, delimiter=0)
self.assertRaises(py_compat_exc, ctor, arg, delimiter='XX')
self.assertRaises(csv.Error, ctor, arg, 'foo')
self.assertRaises(py_compat_exc, ctor, arg, delimiter=None)
self.assertRaises(py_compat_exc, ctor, arg, delimiter=1)
self.assertRaises(py_compat_exc, ctor, arg, quotechar=1)
self.assertRaises(py_compat_exc, ctor, arg, lineterminator=None)
self.assertRaises(py_compat_exc, ctor, arg, lineterminator=1)
self.assertRaises(py_compat_exc, ctor, arg, quoting=None)
self.assertRaises(py_compat_exc, ctor, arg,
quoting=csv.QUOTE_ALL, quotechar='')
self.assertRaises(py_compat_exc, ctor, arg,
quoting=csv.QUOTE_ALL, quotechar=None)
示例2: _test_dialect_attrs
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_ALL [as 别名]
def _test_dialect_attrs(self, ctor, *args):
# Now try with dialect-derived options
class dialect:
delimiter = '-'
doublequote = False
escapechar = '^'
lineterminator = '$'
quotechar = '#'
quoting = csv.QUOTE_ALL
skipinitialspace = True
strict = False
args = args + (dialect,)
obj = ctor(*args)
self.assertEqual(obj.dialect.delimiter, '-')
self.assertEqual(obj.dialect.doublequote, False)
self.assertEqual(obj.dialect.escapechar, '^')
self.assertEqual(obj.dialect.lineterminator, "$")
self.assertEqual(obj.dialect.quotechar, '#')
self.assertEqual(obj.dialect.quoting, csv.QUOTE_ALL)
self.assertEqual(obj.dialect.skipinitialspace, True)
self.assertEqual(obj.dialect.strict, False)
示例3: bale_reg_csvgz
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_ALL [as 别名]
def bale_reg_csvgz(harvest, output_file):
""" bale the data as a gziped csv file"""
logger.info('Output regular data as GZip CSV to %s' % output_file)
with gzip.open(output_file, 'wb') as csv_file:
bale_writer = unicodecsv.writer(csv_file, quoting=unicodecsv.QUOTE_ALL)
# header row
bale_writer.writerow(('entity', 'type', 'direction', 'source', 'notes', 'date'))
bale_writer.writerows(harvest)
示例4: bale_reg_csv
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_ALL [as 别名]
def bale_reg_csv(harvest, output_file):
""" bale the data as a csv file"""
logger.info('Output regular data as CSV to %s' % output_file)
with open(output_file, 'wb') as csv_file:
bale_writer = unicodecsv.writer(csv_file, quoting=unicodecsv.QUOTE_ALL)
# header row
bale_writer.writerow(('entity', 'type', 'direction', 'source', 'notes', 'date'))
bale_writer.writerows(harvest)
示例5: bale_enr_csv
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_ALL [as 别名]
def bale_enr_csv(harvest, output_file):
""" output the data as an enriched csv file"""
logger.info('Output enriched data as CSV to %s' % output_file)
with open(output_file, 'wb') as csv_file:
bale_writer = unicodecsv.writer(csv_file, quoting=unicodecsv.QUOTE_ALL)
# header row
bale_writer.writerow(('entity', 'type', 'direction', 'source', 'notes', 'date', 'asnumber', 'asname', 'country', 'host', 'rhost'))
bale_writer.writerows(harvest)
示例6: bale_enr_csvgz
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_ALL [as 别名]
def bale_enr_csvgz(harvest, output_file):
""" output the data as an enriched gziped csv file"""
logger.info('Output enriched data as GZip CSV to %s' % output_file)
with gzip.open(output_file, 'wb') as csv_file:
bale_writer = unicodecsv.writer(csv_file, quoting=unicodecsv.QUOTE_ALL)
# header row
bale_writer.writerow(('entity', 'type', 'direction', 'source', 'notes', 'date', 'asnumber', 'asname', 'country', 'host', 'rhost'))
bale_writer.writerows(harvest)
示例7: sheet_to_csv
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_ALL [as 别名]
def sheet_to_csv(workbook_path, csv_path, sheet_name):
from pyxform.xls2json_backends import xls_value_to_unicode
wb = xlrd.open_workbook(workbook_path)
try:
sheet = wb.sheet_by_name(sheet_name)
except xlrd.biffh.XLRDError:
return False
if not sheet or sheet.nrows < 2:
return False
with open(csv_path, "wb") as f:
writer = csv.writer(f, quoting=csv.QUOTE_ALL)
mask = [v and len(v.strip()) > 0 for v in sheet.row_values(0)]
for row_idx in range(sheet.nrows):
csv_data = []
try:
for v, m in zip(sheet.row(row_idx), mask):
if m:
value = v.value
value_type = v.ctype
data = xls_value_to_unicode(value, value_type, wb.datemode)
# clean the values of leading and trailing whitespaces
data = data.strip()
csv_data.append(data)
except TypeError:
continue
writer.writerow(csv_data)
return True
示例8: test_write_quoting
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_ALL [as 别名]
def test_write_quoting(self):
self._write_test(['a', 1, 'p,q'], b'a,1,"p,q"')
self.assertRaises(csv.Error,
self._write_test,
['a', 1, 'p,q'], b'a,1,p,q',
quoting=csv.QUOTE_NONE)
self._write_test(['a', 1, 'p,q'], b'a,1,"p,q"',
quoting=csv.QUOTE_MINIMAL)
self._write_test(['a', 1, 'p,q'], b'"a",1,"p,q"',
quoting=csv.QUOTE_NONNUMERIC)
self._write_test(['a', 1, 'p,q'], b'"a","1","p,q"',
quoting=csv.QUOTE_ALL)
self._write_test(['a\nb', 1], b'"a\nb","1"',
quoting=csv.QUOTE_ALL)
示例9: saveSentiment
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_ALL [as 别名]
def saveSentiment(fileToSave,all_predictions,all_scores):
text = ''.join(open("./data/"+fileToSave+".txt").readlines()).decode('utf8')
tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')
book = tokenizer.tokenize(text)
book = [cleanForView(sent) for sent in book]
toOut = zip(book,all_predictions,all_scores)
import unicodecsv as csv
myfile = open(fileToSave+'.csv', 'wb')
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
wr.writerow(["Text","Binary_Sentiment","Cont_Sentiment"])
for row in toOut:
wr.writerow(row)
print "Saved",fileToSave+'.csv'
示例10: main
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_ALL [as 别名]
def main(inDefsFileName, outFileName):
inWordsDict = {}
inWordsList = []
outputWords = []
inDefsWordDetails
with open(inDefsFileName) as inCsvfile:
inWordDefs = csv.DictReader(inCsvfile)
for inWordDef in inWordDefs:
if not exists i
with open(inWordsFileName) as inFile:
for line in inFile:
line = line.strip()
inWordsList.append(line)
for inWord in inWordsList :
rslt = getDef(inWord)
outputWord = {'Chinese' : inWord, 'Pinyin' : '', 'Definition' : ''}
if rslt['success'] :
wordDetails = rslt['word_details']
pinyinList = []
defList = []
for wd in wordDetails:
pinyinList.append(wd['pinyin'])
defList.append(wd['details'])
pinyin = "<br />".join(pinyinList)
definition = "<br />".join(defList)
#print('Chinese : {}, PinYin : {}, Details : {}'.format(inWord, pinyin, definition))
outputWord['Pinyin'] = pinyin
outputWord['Definition'] = definition
else :
print("Failed to fetch details for : {}. Reason : {}".format(inWord, rslt['error']))
outputWords.append(outputWord)
keys = outputWords[0].keys()
with open(outFileName, 'wb') as outFile:
dictWriter = csv.DictWriter(outFile, fieldnames=keys, lineterminator='\n', quoting=csv.QUOTE_ALL)
dictWriter.writeheader()
dictWriter.writerows(outputWords)
#main('1.txt', 'mdbg.csv')