Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write CSV output to stdout?

I know I can write a CSV file with something like:

with open('some.csv', 'w', newline='') as f: 

How would I instead write that output to stdout?

like image 691
jsf80238 Avatar asked May 14 '14 21:05

jsf80238


People also ask

How do I print the output of a csv file?

print() is a function. When you call the print() function it returns the value None. writerow(print()) will write None in the CSV file. If you want to print() a string and write the same string to a file you need to create the string, assign it to a variable, print the variable and write the variable to the file.

What is dialect in csv file?

CSV Dialect defines a simple format to describe the various dialects of CSV files in a language agnostic manner. It aims to deal with a reasonably large subset of the features which differ between dialects, such as terminator strings, quoting rules, escape rules and so on.

What is the output of CSV reader in python?

Example 1: Read CSV files with csv. reader() is used to read the file, which returns an iterable reader object. The reader object is then iterated using a for loop to print the contents of each row.

How do I input a csv file?

On the Data tab, in the Get & Transform Data group, click From Text/CSV. In the Import Data dialog box, locate and double-click the text file that you want to import, and click Import. In the preview dialog box, you have several options: Select Load if you want to load the data directly to a new worksheet.


1 Answers

sys.stdout is a file object corresponding to the program's standard output. You can use its write() method. Note that it's probably not necessary to use the with statement, because stdout does not have to be opened or closed.

So, if you need to create a csv.writer object, you can just say:

import sys spamwriter = csv.writer(sys.stdout) 
like image 109
Lev Levitsky Avatar answered Oct 07 '22 01:10

Lev Levitsky