Guest User

Untitled

a guest
Dec 12th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import csv
  2.  
  3.  
  4. with open("my_file.csv", "w") as f: # with is a context manager, as long as you are in this block, f is an open file
  5. writer = csv.writer(f) # wraps our file (f) in a csv writer. This handles writing to CSV for us.
  6.  
  7. for r in range(5): # This is just to generate some fake data
  8. # writer.writerow takes a list of values to write as one row in the file. The csv writer handles
  9. # formatting the file for you.
  10. writer.writerow((r, r+1, r+2, r+3))
  11.  
  12. # Will create a file called "my_file.csv" with contents
  13. # 0, 1, 2, 3
  14. # 1, 2, 3, 4
  15. # 2, 3, 4, 5
  16. # 3, 4, 5, 6
  17. # 4, 5, 6, 7
Add Comment
Please, Sign In to add comment