SHARE
TWEET

Untitled

a guest Mar 19th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def simple():
  2.     with open("file.txt") as f:
  3.         content = []
  4.         for lines in f:
  5.             content.append(lines.strip().split(","))
  6.         doc_num, date, id, etc = content # define all the contents that are in a line
  7.         # print(doc_num, date, id, etc)
  8.         return doc_num, date, id, etc # Returns data
  9.  
  10. def csv_version():
  11.     """The same but working with csv.
  12.     """
  13.     import os
  14.     import csv
  15.  
  16.     with open("test.csv", newline="") as f:
  17.         reader = csv.reader(f)
  18.         for line in reader:
  19.             print(line)
  20.  
  21. if __name__ == "__main__":
  22.     choose = input("Use simple [1] or csv [2] : ")
  23.     if choose == 1:
  24.         simple()
  25.     elif choose == 2:
  26.         csv_version()
  27.     else:
  28.         return None
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top