Python Forum
How to append a tuple full of records to a dbf file in Python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to append a tuple full of records to a dbf file in Python?
#1
I'm trying to append a tuple full of records into a dbf file that I received from a sql statement but it only produce one record in my tuple. This is my code:


try:            
            DbConnect = '***'
            myDbConn = pymssql.connect("*********","********", "*************",DbConnect)
            cursor = myDbConn.cursor()
            cursor.execute("""select * from payrolldata where busdate>= %s and busdate<=%s ;""",(dteStartDate,m0weekend))
            rows = cursor.fetchall() or []

            for row in rows:
                myTup = tuple(row)



                Dbf = dbf.Table( 'microsdata.DBF', 'id N(7,0); StoNo C(4);BusDate C(20);Position C(20);Ssn C(11); R_HRS N(10,4); Ot_Hrs N(10,4); OthOt_Hrs N(10,4); Oth_Hrs N(10,4); Tips_Pd N(10,4); Tips_Chg N(10,4); Tips_Ind N(10,4); Tips_Dec N(10,4); FirstName C(20); LastName C(20); PayrollId C(10); PayRate N(10,4); RegPay N(10,4)') 
                Dbf.open(mode=dbf.READ_WRITE)
                records = Dbf.append(myTup)
Reply
#2
Could it be that you only receive the last record?
It seems to me that you are creating the same table in a loop over and over again.

Paul
Reply
#3
I put it in that loop because I thought it would loop all my records. When its outside my for loop it shows no records in my dbf file.
Reply
#4
I'm trying to append tuple into my dbf file as records but it only gets the last line of my tuple.

 table = dbf.Table( 'empInfo.DBF', 'SSN C(11); STOREID C(4);Payrollid C(10); EmpId C(10); Fname C(20); Lname C(20)') 
 table.open(mode=dbf.READ_WRITE)
 rec = tuple(rows)
 print(rec)
Reply
#5
I'm trying to append a tuple for multiple records but I only get the last record of my tuple.
table = dbf.Table( 'empInfo.DBF', 'SSN C(11); STOREID C(4);Payrollid C(10); EmpId C(10); Fname C(20); Lname C(20)') 
table.open(mode=dbf.READ_WRITE)

rec = tuple(rows)

table.append(rec)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to make a test data file for the full length of definition? MDRI 6 969 Apr-16-2021, 01:47 AM
Last Post: MDRI
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 871 Nov-04-2020, 11:26 AM
Last Post: Aggam
  Rename docx file from tuple gjack 2 530 Oct-20-2020, 05:33 PM
Last Post: gjack
  How to append to a set in Python dgrunwal 7 1,067 Oct-01-2020, 04:27 PM
Last Post: ndc85430
  How do I get full XPath extract using Python? MDRI 1 763 Sep-18-2020, 02:13 AM
Last Post: MDRI
  Including modules in Python using sys.path.append JoeDainton123 1 918 Aug-24-2020, 04:51 AM
Last Post: millpond
  Python Error- TypeError: ('Params must be in a list, tuple, or Row', 'HY000') DarkCoder2020 3 1,899 Jul-29-2020, 12:02 AM
Last Post: Larz60+
  Append JSON's and write to file faqsap 4 1,312 May-15-2020, 04:20 PM
Last Post: faqsap
  Cant Append a word in a line to a list err "str obj has no attribute append Sutsro 2 888 Apr-22-2020, 01:01 PM
Last Post: deanhystad
  Copy and append data from .dat file Makada 17 3,636 Jan-20-2020, 08:33 PM
Last Post: Makada

Forum Jump:

User Panel Messages

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