store all variable values into list and insert to sql_summary table - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: store all variable values into list and insert to sql_summary table (/thread-38315.html) |
store all variable values into list and insert to sql_summary table - mg24 - Sep-27-2022 Hi Team, I am working on a project, task is 1) extract sql table into csv 2) run chksum on it 3) gzip the file and final steps to pass all varaibles value into sql_Summary_tables. how to store all values into a global list , and insert values into sql_Summary_tables. I am using 4 modules, all variable values lies in different module I am not using oops concept. created functions in different module and calling. plz help how to achieve this task. attached sample of office task. import sys def main() SQL_Table = sys.argv(1) Destination_path = sys.argv(2) site_Name = sys.argv(3) date = sys.argv(4) from module1 import Create_csv csvname = Create_csv(tblname,SQL_Table,Destination_path) from module2 import chksum x = Create_checksum(tblname,Destination_path) from module3 import function_gzip y = function_gzip((tblname,Destination_path) from module4 import insert_Records sql = """ insert into summary_table([database],tblname,Destination_path,date,chksumNo,Gzip_status)values([database],tblname,Destination_path,date,x,y) if __name__ == "__main__": def main() RE: store all variable values into list and insert to sql_summary table - Larz60+ - Sep-28-2022
RE: store all variable values into list and insert to sql_summary table - mg24 - Sep-28-2022 Hi Team, thanks for the information modified after suggestion, how to put below code into class module. import gzip import hashlib import sqlite3 import sys from module4 import insert_Records from module1 import Create_csv from module2 import chksum from module3 import function_gzip def main(SQL_Table, Destination_path, site_Name, date) csvname = Create_csv(tblname, SQL_Table, Destination_path) x = Create_checksum(tblname, Destination_path) y = function_gzip((tblname, Destination_path) sql = f"insert into summary_table([database], tblname, Destination_path, date, chksumNo, Gzip_status) values ('{database}','{tblname}','{Destination_path'},'{date}','{x}','{y}')" if __name__ == "__main__": SQL_Table = sys.argv(1) Destination_path = sys.argv(2) site_Name = sys.argv(3) date = sys.argv(4) RE: store all variable values into list and insert to sql_summary table - Larz60+ - Sep-28-2022 This will create a class, albeit a simple one. import gzip import hashlib import sqlite3 import sys from module4 import insert_Records from module1 import Create_csv from module2 import chksum from module3 import function_gzip class Myclass: def create_table(self, SQL_Table, Destination_path, site_Name, date) csvname = Create_csv(tblname, SQL_Table, Destination_path) x = Create_checksum(tblname, Destination_path) y = function_gzip((tblname, Destination_path) sql = f"insert into summary_table([database], tblname, Destination_path, date, chksumNo, Gzip_status) values ('{database}','{tblname}','{Destination_path'},'{date}','{x}','{y}')" def main(argv): # instanceiate class mc = Myclass() SQL_Table = argv(1) Destination_path = argv(2) site_Name = argv(3) date = argv(4) mc.create_table(SQL_Table, Destination_path, site_Name, date) if __name__ == "__main__": main(sys.argv)This code has not been tested as I don't have the code for module1, module2, etc. You should be using argparse for command line arguments, see: https://docs.python.org/3/howto/argparse.html again, give your 'modules' meaningful names rather than module4, module1, etc |