Python Forum
store all variable values into list and insert to sql_summary table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
store all variable values into list and insert to sql_summary table
#1
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()
Reply
#2
  • move all imports to top of script.
  • You should use better (meaningful) names for your modules
  • Code doesn't reflect what you state as goal (inserting into database, rather than querying same)
  • not enough information supplied to comment further. Suggest displaying content of all modules.
Reply
#3
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)
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copying the order of another list with identical values gohanhango 7 1,062 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,147 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Comparing List values to get indexes Edward_ 7 1,083 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Insert 10gb csv files into sql table via python mg24 2 1,831 Apr-28-2023, 04:14 PM
Last Post: snippsat
  Adding values with reduce() function from the list of tuples kinimod 10 2,513 Jan-24-2023, 08:22 AM
Last Post: perfringo
  user input values into list of lists tauros73 3 1,023 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Photo How to select NULL and blank values from MySQL table into csv python300 9 2,328 Dec-27-2022, 09:43 PM
Last Post: deanhystad
Question Triying to store values from models Larry1888 1 632 Nov-02-2022, 02:08 AM
Last Post: Pedroski55
  Split string using variable found in a list japo85 2 1,236 Jul-11-2022, 08:52 AM
Last Post: japo85
  Insert into SQL Table only when Table is First Created? Extra 4 1,409 Jun-28-2022, 07:50 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020