Python unicodecsv.QUOTE_ALL Examples

The following are 10 code examples of unicodecsv.QUOTE_ALL(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module unicodecsv , or try the search function .
Example #1
Source File: test.py    From pyRevit with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #2
Source File: test.py    From pyRevit with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #3
Source File: baler.py    From combine with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #4
Source File: baler.py    From combine with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #5
Source File: baler.py    From combine with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #6
Source File: baler.py    From combine with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #7
Source File: utils.py    From pyxform with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 
Example #8
Source File: test.py    From pyRevit with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #9
Source File: getSentiment.py    From DNN-Sentiment with MIT License 5 votes vote down vote up
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' 
Example #10
Source File: mdbg.old.py    From anki-deck-for-duolingo-chinese with MIT License 4 votes vote down vote up
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')