rodrigosantosbr

[Py] CSV - how to read

Jan 11th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. ---------------------------------------------------------
  2. fornecedores_ce.csv
  3. ---------------------------------------------------------
  4.  
  5. cnpj;razao_social;nome_fantasia;cpf;uf;municipio;telefone;email;excluido
  6. 07816912000185;1AARON COMERCIO DE INSTALACOES COMERCIAIS E ESCRITORIO LTDA - ME;KIUBA;;CE;Fortaleza;;;false
  7. 13056090000184;2 K CONSTRUCOES E SERVICOS EIRELI - EPP;2 K CONSTRUCOES ELETRIFICACAO E SERVICOS LTDA.;;CE;Boa Viagem;;;false
  8. 07656795000130;2A CONSTRUCOES LTDA;;;CE;Fortaleza;;;false
  9.  
  10. ---------------------------------------------------------
  11. test.py
  12. ---------------------------------------------------------
  13.  
  14. import csv
  15.  
  16. pathfile = os.path.dirname(os.path.abspath(__file__))+'/'+'fornecedores_ce.csv'
  17. with open(pathfile, mode='r', encoding="UTF-8") as csv_file:
  18.     csv_reader = csv.DictReader(csv_file, delimiter=';')
  19.     line_count = 1
  20.     for row in csv_reader:
  21.         if line_count > 1:
  22.                 razao_social = row['razao_social']
  23.                 nome_fantasia = row['nome_fantasia']
  24.                 cnpj = row['cnpj']
  25.                 cpf = row['cpf']
  26.                 uf = row['uf']
  27.                 municipio = row['municipio']
  28.                 telefone = row['telefone']
  29.                 email = row['email']
  30.                 thislist.append(DDL(sql_insert_pj(razao_social, nome_fantasia, cnpj, cpf, uf, municipio, telefone, email)))
Add Comment
Please, Sign In to add comment