SHARE
TWEET

Untitled

a guest Jun 12th, 2019 113 in 10 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import csv
  2. import pyodbc
  3. import configparser, logging
  4.  
  5. file_name = "D:\\test\\test.csv"
  6.  
  7.  
  8. def csv_reader(self):
  9.     reader = csv.reader(self)
  10.     clients = []
  11.     for row in reader:
  12.         clients += [[cell for cell in row]]
  13.     return clients
  14.  
  15.  
  16. if __name__ == "__main__":
  17.     csv_path = "D:\\test\\test.csv"
  18.     with open(csv_path, "r") as file_name:
  19.         print(csv_reader(file_name))
  20.  
  21. config = configparser.ConfigParser()
  22. try:
  23.     config.read('D:\\test\\ini\\ini.txt')
  24. except Exception as e:
  25.     logging.info(e)
  26.     exit
  27.  
  28. server = config['Default']['server']
  29. database = config['Default']['database']
  30. username = config['Default']['username']
  31. password = config['Default']['password']
  32.  
  33. conn_str = ('DRIVER={SQL Server}'+
  34.     ';SERVER='+server+
  35.     ';DATABASE='+database+
  36.     ';UID='+username+
  37.     ';PWD='+password)
  38.  
  39. cnxn = pyodbc.connect(conn_str)
  40. cursor = cnxn.cursor()
  41.  
  42. rows = cursor.execute('''SELECT ID FROM CLIENTS WHERE ENABLED = 1''').fechall()
  43.  
  44. for row in rows:
  45.     print(row)
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
 
Top