本文整理匯總了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')