def b_fcsv_writerow(bm): for i in bm: writer = fcsv.writer( 'b_fcsv.csv') # , quoting=csv.QUOTE_NONNUMERIC) writer.writerow(source[0]) writer.writerow(source[1]) writer.writerow(source[2])
def write_list(): writer = fcsv.writer('v.csv') writer.writerow(("Hello", "こんにちは", "csv")) writer.writerows(( ("Hello1", "こんにちは1", "csv1"), ("World2", "せかい2", "csv2"), ))
def write_tuple(): writer = fcsv.writer('v.csv') writer.writerow(["Hello", "こんにちは", "csv"]) writer.writerows([ ["Hello1", "こんにちは1", "csv1"], ("World2", "せかい2", "csv2"), ])
def test_writer_opt_delimiter_verticalbar(self): rowdata = [1, 2, -4.1, "Hello", True, False, None] # fcsv w = fcsv.writer(self.fo.name, delimiter="|") w.writerow(rowdata) with open(self.fo.name) as f: ret = f.read().strip() self.assertEqual("1|2|-4.1|Hello|True|False|", ret) # std with open(self.fo.name, 'w') as f: w = csv.writer(f, delimiter="|") w.writerow(rowdata) # validation with open(self.fo.name) as f: std_ret = f.read().strip() self.assertEqual(ret, std_ret)
def test_writer_opt_dialect_and_delimiter(self): rowdata = [1, 2, -4.1, "Hello", True, False, None] # fcsv w = fcsv.writer(self.fo.name, dialect="excel", delimiter=";") w.writerow(rowdata) with open(self.fo.name) as f: ret = f.read().strip() self.assertEqual("1;2;-4.1;Hello;True;False;", ret) # std with open(self.fo.name, 'w') as f: w = csv.writer(f, dialect="excel", delimiter=";") w.writerow(rowdata) with open(self.fo.name) as f: std_ret = f.read().strip() # validation self.assertEqual(ret, std_ret)
def test_writer_with_list(self): rowdata = [1, 2, -4.1, "Hello", True, False, None] # fcsv w = fcsv.writer(self.fo.name) w.writerow(rowdata) with open(self.fo.name) as f: ret = f.read().strip() self.assertEqual("1,2,-4.1,Hello,True,False,", ret) # std with open(self.fo.name, 'w') as f: w = csv.writer(f) w.writerow(rowdata) # validation with open(self.fo.name) as f: std_ret = f.read().strip() self.assertEqual(ret, std_ret)