How to write CSV output to stdout?

前端 未结 1 1146
长情又很酷
长情又很酷 2021-02-11 11:46

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

相关标签:
1条回答
  • 2021-02-11 12:30

    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)
    
    0 讨论(0)
提交回复
热议问题