Link to home
Start Free TrialLog in
Avatar of jameskane
jameskane

asked on

python string conversion

I have a string:
'Counter({8: 3, 7: 3, 9: 1, 10: 1})'

I want to remove the ''  from the string and have
Counter({8: 3, 7: 3, 9: 1, 10: 1})

just can't figure out how to do this !!

thanks for your help !
SOLUTION
Avatar of Mark Brady
Mark Brady
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pepr
pepr

To add to Mark's comment... If the code is not to be executed only once (say it contains some more general expression), you may want to store it for the repeated execution as a compiled object. For that purpose, you may want to compile() built-in function.

For the case you really want to remove only the first and last character from a string, you want to get the slice of it -- using the  slice notation. If s is your string, then s[1:-1] is another string without the first and without the last characters.
Avatar of jameskane

ASKER

Marc and pepr many thanks for the input. As you suggested, I should give this a bit more context.  

I have 3 pages involved in this. In summary, the problem relates to two variables which I am trying to pass via hidden form fields. I need to pass  add_cnt and drop_cnt from the first page through the second page and make them and their values available to the third page. Note that this third page involves tables, one of which  is a version of the table in page 1. So, I am really trying to duplicate the page 1 table on page 3.

Page 1 table is working perfectly. The problem I have is getting add_cnt  and drop_cnt and their values to be made available to page 3.

The two variables

The first page (action_orderformTWO.cgi) uses
drop_cnt = counter()
add_cnt = counter({8:3,7:3,9:1,10:1}) (note the values are example values)
I need these to turn up, exactly the same page 3.
See attached an image of the output from page 1. At the top you will see printouts of the variables and their values used in the creation of the page.
See also the code for page 1. You will see that I am passing the two variables via form
hidden fields. Again, this page works


The second page is pay_receipt.cgi  and this is a form used for recording the client payments in relation to the chosen courses summarized in the table of the First page. This page is functioning correctly. I simply passes on the two variable received from page 1 using form hidden fields in exactly the same way page 1.
I am attaching an image of the output from this page - at the top you will see the values it has received for add_cnt and drop_cnt.  
add_cnt = ['Counter({8: 3, 7: 3, 9: 1, 10: 1})', 'Counter()']
drop_cnt = None

The third page action_pay_receipt_purch.cgi is in progress and is the action page for pay_receipt.cgi. This is where I am having the problem.  I am attaching an image of the page output (error page) and you will see at the top the values I get for add_cnt and drop_cnt are
add_cnt = ['Counter({8: 3, 7: 3, 9: 1, 10: 1})', 'Counter()']
drop_cnt =None

In summary, I need to be able to rework the value of add_cnt which appears on page 3 to be exactly the same as its value on page 1

PAGE 1  
drop_cnt = counter()
add_cnt = counter({8:3,7:3,9:1,10:1}) (note the values are example values)

PAGE 3 ... current
drop_cnt =None ........ should be counter() ??????
add_cnt = ['Counter({8: 3, 7: 3, 9: 1, 10: 1})', 'Counter()'] .... I can pull out the first list component as follows on the shell:

add_cnt = ['Counter({8: 3, 7: 3, 9: 1, 10: 1})', 'Counter()']
add_cnt_one = add_cnt[0]
add_cnt_one
'Counter({8: 3, 7: 3, 9: 1, 10: 1})'

 ..... which is what I used on page one, except it is a string.

Sorry, this is a bit long, but hopefully gives you the context.






PAGE 1 CODE
#!C:\Python34\python.exe
import collections
import cgi
import cgitb
import mysql.connector as conn
import datetime
def htmlTop():
    print("""Content-type:text/html\n\n
        <!DOCTYPE html>
        <html lang="en">
            <head>
                <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
                <title> My Server-side template</title>
        <style type='text/css'>
         
       
    
        #container {
                position:absolute;
                left:50%;
                top:50%;
                width:909px;
                height:500px;
                margin-left: -454px;
                margin-top: -250px;
                z-index:1;
                background-color: #D9F2F0;
                text-align:center;
        }
        
       
        
        </style>

        <script type='text/javascript' src='js/jquery.js'></script> <!--//this is the jquery magic-->
        <script type='text/javascript'> //this is the jquery plugin for aligning the image vertically
            $(window).load(function(){
                /*we are using $(window).load() here because we want the coding to take
                effect when the image is loaded. */
                
                //get the width of the parent
                var parent_height = $('#the_image').parent().height();
                var image_height = $('#the_image').height();
                
                var top_margin = (parent_height - image_height)/2;
                
                //center it
                $('#the_image').css( 'margin-top' , top_margin);
            });
        </script>


            </head>
    <body>""")

def htmlTail():
    print(""" its done</body>
        </html>""")
    
    
def frenchdate(): 
    #import datetime must be included at top of page
    now = datetime.datetime.now()
    year = now.year
    month = now.month
    day = now.day
    # PRINTING THE DATE IN FORMAT Janvier 3, 2015 - which is correct for France. (vrs 3, January, 2015 for english)
    # NOTE DOES NOT WORK AT THE MOMENT IF YOU USE SPECIAL CHARACTERS - even within # !!!       
    months = ('janvier', 'fevrier', 'mars', 'avril', 'mai', 'juin', 'juillet', 'aout', 'septembre', 'octobre', 'novembre', 'decembre')
    month = month=months[now.month-1]
    day=now.day
    year=now.year
    return month, day, year

    
    


def connectDB():
    db=conn.connect(host='localhost' ,user='root' ,passwd='844cheminduplan' ,db='office')
    cursor = db.cursor()
    return db, cursor 
    

def getData():
    formData = cgi.FieldStorage()
    #selection = formData.getlist('selection')
    selection = formData.getlist('selection')
    selectionTWO = formData.getlist('selectionTWO')
    selectionTHREE = formData.getlist('selectionTHREE')
    memberID = formData.getlist('memberID')
    return selection,selectionTWO,selectionTHREE,memberID

# This function below is to select the T1ytd, T2ytd and T3ytd values from table registations. These are
# are to be used with the T1ytdlatest, T2ytdlatest, T3ytdlatest values to determine the delta
# purchases and also the revised values for T1ytd.... etc

def SelectfromDB(db,cursor):
    cursor.execute("""select T1ytd,T2ytd,T3ytd,ALPAID_ytd from registrations WHERE memberID = "%s" """
    %(memberID)) 
    order_ytd=cursor.fetchall()
    return order_ytd 




def killcommasselection(selection):
    newlist =[]
    for m in selection:
        MC= int(m[:])
        newlist.append(MC)
        selection = newlist
    return selection



def killcommasselectionTHREE(selectionTHREE):
    newlist =[]
    for m in selectionTHREE:
        MC= int(m[:])
        newlist.append(MC)
        selectionTHREE = newlist
    return selectionTHREE



def killcommasselectionTWO(selectionTWO):
    newlist =[]
    for m in selectionTWO:
        MC= int(m[:])
        newlist.append(MC)
        selectionTWO = newlist
    return selectionTWO


    

    

#-------------------------------------------------------------------------------------------------------------------    
# NOTE on the following two update functions.  UpdateInfo2 updates the columns T1ytdlatest,  T2ytdlatest, T3ytdlatest 
#wheras UpdateInfo1 updates T1ytd, T2ytd and T3ytd. Remember how this wworks  - the very first  update to Registrations
# is to the ytdlatest columns. Immediately after that the delta order and ytd orders and receipts are done by netting 
# together the values of ytd and tydlates columns. Initially for the first order the ytd colums are blank []'s.
# AFTER THE RECEIPT AND MEMBER STATUS ARE UPDATED - THEN - UpdateInfo1 is run to update ytd columns. At this moment 
#the ytd and ytdlatest columns are the same values.

#On the next update cycle, as for the first, the ytdlatest columns are updated first. Then the delta calculations are done
#for the recipts and after that, the ytd columns are updated.

# NOTE ALSO that mylist contains all the informaton for updating.

# Note on  structure of the update function.  The SET and WHERE lines use '{0}', '{1}', '{2}', '{3}' - think of these
# as buckets. We define the content of the buckets via the .format line. In this line we select the values to be stored
# in the buckets. The .format values need to be lined up with the names given to the {}'s. So for example mylist[0] must 
#be the last one of the format string as it needs to corrospond with the last item in the SET/WHERE lines above.
    
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest='{0}', T2ytdlatest='{1}', T3ytdlatest='{2}'
       WHERE memberID={3}
    """.format(mylist[1], mylist[2], mylist[3],mylist[0]))
    db.commit()
    db.close 
    
def UpdateInfo1(db,cursor):#see note at bottom of page  on use of mylist_DUPLICATE
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytd='{0}', T2ytd='{1}', T3ytd='{2}'
       WHERE memberID={3}
    """.format(mylist_DUPLICATE[1], mylist_DUPLICATE[2], mylist_DUPLICATE[3],mylist_DUPLICATE[0]))
    db.commit()
    db.close
    
def UpdateEnrolStatus(db,cursor): # to flag that member has paid enrollement fee
    db,cursor=connectDB()
    cursor.execute ("""
        UPDATE registrations
        SET  Enrol_Status='{0}' 
        WHERE memberID={1}
    """.format(1, mylist_DUPLICATE[0]))
    db.commit()
    db.close    
#-----------------------------------------------------------------------------------------------------

def deltacalculate (T1ytd,T2ytd,T3ytd,T1ytdlatest,T2ytdlatest,T3ytdlatest):
    T1delta_dropped=[x for x in T1ytd if not x in T1ytdlatest]
    T1delta_nochange=[x for x in T1ytd if x in T1ytdlatest]
    T1delta_added=[x for x in T1ytdlatest if not x in T1ytd]
    
    T2delta_dropped=[x for x in T2ytd if not x in T2ytdlatest]
    T2delta_nochange=[x for x in T2ytd if x in T2ytdlatest]
    T2delta_added=[x for x in T2ytdlatest if not x in T2ytd]
    
    T3delta_dropped=[x for x in T3ytd if not x in T3ytdlatest]
    T3delta_nochange=[x for x in T3ytd if x in T3ytdlatest]
    T3delta_added=[x for x in T3ytdlatest if not x in T3ytd] 
    
    dropped = T1delta_dropped + T2delta_dropped + T3delta_dropped
    added = T1delta_added + T2delta_added + T3delta_added
    nochange = T1delta_nochange + T2delta_nochange + T3delta_nochange    
    return (dropped, added, nochange)


def dropcounter(dropped, added):
    import collections
    add_cnt = collections.Counter(added)
    new_dropped = []
    for value in dropped:
        in_add_cnt = add_cnt.get(value, 0)
        if in_add_cnt:
            added.remove(value) # preserves the order, but is a little costly
            add_cnt[value] -= 1
        else:
            new_dropped.append(value)
    dropped =  new_dropped
    drop_cnt = collections.Counter(dropped)
    return drop_cnt,dropped

    
def addcounter(dropped, added):
    import collections
    drop_cnt = collections.Counter(dropped)
    new_added = []
    for value in added:
        in_drop_cnt = drop_cnt.get(value, 0)
        if in_drop_cnt:
            dropped.remove(value) # preserves the order, but is a little costly
            drop_cnt[value] -= 1
        else:
            new_added.append(value)
    added =  new_added
    add_cnt = collections.Counter(added)   
    return add_cnt,added

    
def nochangecounter(nochange):
    import collections
    nochange_cnt = collections.Counter(nochange)
    return nochange_cnt

def OrderProfiler(mylist,db,cursor):
    # provides a list of 1s nd 0eros to describe the list in terms of paid and activity libre activities
    OrderProfile = []
    #del mylist[0] # chopping off the memberID
    mylist = mylist[1]  +  mylist[2]  + mylist[3]
    print(mylist, "this is mylist")
    for each in mylist:
        courseNumber = each
        activitydata =  activityinfo(db,cursor,courseNumber)
        #print(activitydata, "this is activity data")
        #Note activitydata[0][2] is price for 12 trim and activitydata[0][3] is for 36 trim
        if activitydata[0][2] == 0 and activitydata[0][3] == 0:
            OrderProfile.append(0) #activityLibre
        elif activitydata[0][2] >0 and activitydata[0][3] > 0:
            OrderProfile.append(1) # paid
    return OrderProfile
    
def StatusFinder (OrderProfile):
    # declares an order as being mixed (0), activity libre only(1) or paid only(2) items
    # uses OrderProfile list from OrderProfiler(mylist, db, cursoro) above
    # this status along with the ALPAID_YTD flag  in registrations table determines if DELTA ORDER should be
    # charged the activity libre registration fee, or should be reimboursed the activity libre registration fee
    print (collections.Counter(OrderProfile))
    OrderProfileCount = (collections.Counter(OrderProfile))
    if OrderProfile.count(1) >0 and OrderProfile.count(0) >0:
        print(OrderProfile, "OrderProfile")
        status = 0 #mixed
    elif OrderProfile.count(1) >0 and OrderProfile.count(0)== 0:
        status = 2 #paid_only
    elif OrderProfile.count(1) ==0 and OrderProfile.count(0)>0:
        status = 1 #free_only
    return status


def confirmpurchase():
    SwitchOn = 0
    SwitchOff = 0
    
    print("<div id='container'>")
    #print("<table width='909' border='1' cellspacing='0' cellpadding='0' >")
    print("<table width='909' border='1' cellpadding='1' cellspacing='1' bordercolor='#FFFFFF' bgcolor='#ECF4F4'>")
    print("<tr bgcolor='#FFFFFF'>")
    print("<th align= left colspan='4'>{civilites} {Prenom} {Nom}</th>".format(civilites = civilites, Prenom = Prenom, Nom = Nom))
    print("</tr>")
    print("<tr bgcolor='#FFFFFF'>")
    print("<td align= left colspan='4'>{Adresse} </td>".format(Adresse = Adresse))
    print("</tr>")
    print("<tr bgcolor='#FFFFFF'>")
    print("<td align= left colspan='4'>{ZIP} {Ville} </td>".format(ZIP = ZIP, Ville = Ville))
    print("</tr>")  
    print("<tr bgcolor='#FFFFFF'>")
    print("<td align= left colspan='4'></td>")
    print("</tr>")      
    print("<tr bgcolor='#FFFFFF'>")
    print("<td align= left colspan='4'></td>")
    print("</tr>")    
    
    print("<tr bgcolor='#D9F2F0'>")
    print("<th colspan='4' scope='row' align='left'> VOTRE PANIER D'ACHET :- {month} {day}, {year}</th>".format(month=month, day=day, year=year))
    print("</tr>")    
    print("<tr bgcolor='#B1D1D1'>")
    print("<th width='130' scope='row' align=center>ACTIVITE #</th>")
    print("<td width='426' align=center>DESCRIPTION </td>")
    print("<td width='130' align=center>TRIMESTRES</td>")
    print("<td width='78' align=center>PRIX (EURO)</td>")
    print("</tr>")        
    
    
    Delta_euro_total = 0
    if len(add_cnt) != 0:
        for each in add_cnt:
            print("<tr>")
            courseNumber = each
            activityinfo(db,cursor,courseNumber)
            activitydata = activityinfo(db,cursor,courseNumber)
            print("<td align=center>{0}</td>".format(activitydata[0][0]))
            print("<td align=center>{0}</td>".format(activitydata[0][1]))
            print("<td align=center>{0}</td>".format(add_cnt[each]))
            if add_cnt[each] == 3:
                print("<td align=center>{0}</td>".format(activitydata[0][3])) #using tariff36 pricing
                Delta_euro_total = Delta_euro_total + activitydata[0][3]
            else:
                print("<td align=center>{0}</td>".format(add_cnt[each]*activitydata[0][2]))
                Delta_euro_total = Delta_euro_total + add_cnt[each]*activitydata[0][2]
            print("</tr>")
            
            
    if len(drop_cnt) != 0:
        for each in drop_cnt:
            print("<tr>")
            courseNumber = each
            activityinfo(db,cursor,courseNumber)
            activitydata = activityinfo(db,cursor,courseNumber)
            print("<td align=center>{0}</td>".format(activitydata[0][0]))
            print("<td align=center>{0}</td>".format(activitydata[0][1]))
            print("<td align=center>{0}</td>".format(-drop_cnt[each]))            
            
            if drop_cnt[each] == 3:
                print("<td align=center>{0}</td>".format(-activitydata[0][3])) #using tariff36 pricing
                Delta_euro_total = Delta_euro_total - activitydata[0][3]
                
            else:
                print("<td align=center>{0}</td>".format(-drop_cnt[each]*activitydata[0][2]))
                Delta_euro_total = Delta_euro_total - drop_cnt[each]*activitydata[0][2]
                
            print("</tr>")
            
            
            
            
    if ALPAID_ytd != 1 and status == 1: #free only
        print("<tr>")
        print("<td colspan=3 scope=row align=center>Registration Activite Libre</td>")
        print("<td align=center>{0}</td>".format(activity_libre))
        Delta_euro_total = Delta_euro_total + activity_libre
        Turn_On_Alibe(db,cursor)#turns on the switch ALPAID_ytd       
        print("</tr>")            
            
            
     
    elif ALPAID_ytd != 0 and status == 0: #mixed
        print("<tr>")
        print("<td colspan=3 scope=row align=center>Reimbourse Registration Activite Libre</td>")
        print("<td align=center>{0}</td>".format(-activity_libre)) 
        Delta_euro_total = Delta_euro_total - activity_libre
        Turn_Off_Alibe(db,cursor)#turns off the switch ALPAID_ytd
        print("</tr>")       
    
           
        
    elif ALPAID_ytd != 0 and status == 2: #paid only
        print("<tr>")
        print("<td colspan=3 scope=row align=center>Reimbourse Registration Activite Libre</td>")
        print("<td align=center>{0}</td>".format(-activity_libre)) 
        Delta_euro_total = Delta_euro_total - activity_libre
        Turn_Off_Alibe(db,cursor)#turns off the switch ALPAID_ytd
        print("</tr>")
        
        
    if (currentyear - naissance) < 17 and Enrol_Status == 0:
        print("<tr>")
        print("<td colspan=3 scope=row align=center>Tarif de L'adhesion (Junior)</td>")
        Delta_euro_total = Delta_euro_total + Enroll_junior
        UpdateEnrolStatus(db,cursor)
        print("<td align=center>{0}</td>".format(Enroll_junior)) 
        print("</tr>")
        
    elif Enrol_Status == 0 :
        print("<tr>")
        print("<td colspan=3 scope=row align=center>Tarif de L'adhesion (Adult)</td>")
        Delta_euro_total = Delta_euro_total + Enroll_adult
        UpdateEnrolStatus(db,cursor)
        print("<td align=center>{0}</td>".format(Enroll_adult)) 
        print("</tr>")        
        
    
    print("<tr>") # this is the row that gives the total cost
    print("<td colspan=3 scope=row align=right>TOTAL COST......</td>")
    print("<td align=center>{0}</td>".format(Delta_euro_total))
    print("</tr>")    
    
    
    print("<tr>") # this is the row that gives the buttons
    
    print("<td scope= 'col'>")
    print("""<form method="post" action="Pay_Receipt.cgi">""")
    print("""<input type='hidden' name='mylist' id='mylist' value="{0}" />""".format(mylist))
    print("""<input type='hidden' name='Delta_euro_total' id='Delta_euro_total' value="{0}" />""".format(Delta_euro_total))
    print("""<input type='hidden' name='mylist' id='currentyear' value="{0}" />""".format(currentyear))
    print("""<input type='hidden' name='mylist' id='naissance' value="{0}" />""".format(naissance))
    print("""<input type='hidden' name='mylist' id='Enrol_Status' value="{0}" />""".format(Enrol_Status))
    print("""<input type='hidden' name='mylist' id='ALPAID_ytd' value="{0}" />""".format(ALPAID_ytd))
    print("""<input type='hidden' name='mylist' id='status' value="{0}" />""".format(status))
    print("""<input type='hidden' name='add_cnt' id='add_cnt' value="{0}" />""".format(add_cnt))
    print("""<input type='hidden' name='add_cnt' id='drop_cnt' value="{0}" />""".format(drop_cnt))
    
    
    print("""<input type="submit" name="dfgsdf" ID="dfgfgd" value="Continuer Enregistrement" />""")    
    print("</form>") 
    
    print("</td>")
    print('<td><a href="orderformtwo_revise.CGI?memberID={memberID}">CHANGEZ VOTRE SELECTION</a></td>'.format(memberID=memberID))
    print("</td>")
    
    print("</tr>")    
    
    print("</table>") 
    print("</div>")
    return Delta_euro_total,SwitchOff,SwitchOn


def Turn_On_Alibe(db,cursor):#used above for turning on the ALPAID_ytd switch
    db,cursor=connectDB()
    cursor.execute ("""
       UPDATE registrations
       SET  ALPAID_ytd=1
       WHERE memberID={0}
    """.format(mylist[0]))
    db.commit()
    db.close

def Turn_Off_Alibe(db,cursor): #used above for turning on the ALPAID_ytd switch
    db,cursor=connectDB()
    cursor.execute ("""
       UPDATE registrations
       SET  ALPAID_ytd=0
       WHERE memberID={0}
    """.format(mylist[0]))
    db.commit()
    db.close






def SelectALPAID_ytd(db,cursor): #picks out the value of ALPAID_ytd from registration table
    cursor.execute("""select ALPAID_ytd from registrations WHERE memberID = "%s" """
    %(memberID)) 
    ALPAID_ytd=cursor.fetchall()
    return ALPAID_ytd

def Select_Enrol_Status(db,cursor): #picks out the value of Enrol_Status to determine if enrollement fee charged
    cursor.execute("""select Enrol_Status from registrations WHERE memberID = "%s" """
    %(memberID)) 
    Select_Enrol_Status =cursor.fetchall()
    return Select_Enrol_Status    
    

def SelectActivityLibre(db,cursor): #picks out the value activity libre registration charge form fees table
    cursor.execute ("""SELECT activity_libre from fees""")
    activity_libre=cursor.fetchall()
    return activity_libre

def SelectEnroll(db,cursor): #picks out the values Enroll_adult and Enroll_Junior form fees table
    cursor.execute ("""SELECT Enroll_adult, Enroll_junior from fees""")
    Enroll=cursor.fetchall()
    return Enroll








def euro_activityCnt(mylist): # This calculates the total cost of the new client order. 
    #It is complicated by fact that the cost of registering for an activity over 3 Trimesters
    # is the same as it would be if you only signed up for two trimesters - in other words
    # sign up for 2 and get the third for free. Alternatively if you sign up only quartey by
    #quarter then you do not get this price break.
    total_euro=0
    activityCount=0
    print(mylist, "this is mylisst1")
    print(mylist[0],"this is mylist[0]")
    del mylist[0]
    print(mylist, "this is my list after mylist[0]")
    mylist = mylist[0] + mylist[1]  + mylist[2]
    print(mylist, "this is my list2")
    count = collections.Counter(mylist)
    #print(count, "this is the counter")
    for each in count:
        del mylist[0]
        courseNumber = each
        activityCount = activityCount + count[each]
        activityinfo(db,cursor,courseNumber)
        activitydata = activityinfo(db,cursor,courseNumber)
        #print(activitydata, "this is activity data")
        if count[each] != 3:
            total_euro = total_euro + count[each]*activitydata[0][2]
        else:
            total_euro= total_euro + activitydata[0][3]
    return total_euro,activityCount,count


def activityinfo(db,cursor,courseNumber):
    cursor.execute("""select courseNumber,Activity, tariffstwelve, tariffsthirtysix from activities WHERE courseNumber = "%s" """
    %(courseNumber)) 
    activityinfo=cursor.fetchall()
    return activityinfo

def JuniorCheck(db,cursor):
    cursor.execute("""select Naissance from members2 WHERE memberID = "%s" """
    %(memberID)) 
    JuniorCheck=cursor.fetchall()
    return JuniorCheck 

def PersonInfo(db,cursor): # this to grab info on person whose order is being processed
    cursor.execute("""select civilites, Nom, Prenom, Adresse, ZIP, Ville from members2 WHERE memberID = "%s" """
    %(memberID)) 
    person=cursor.fetchall()
    return person 
    
#main program
if __name__== "__main__":
    try:
        htmlTop()
        db,cursor=connectDB()
        selection,selectionTWO,selectionTHREE,memberID = getData()
        killcommasselection(selection)
        selection = killcommasselection(selection)
        killcommasselectionTWO(selectionTWO)
        selectionTWO = killcommasselectionTWO(selectionTWO)
        killcommasselectionTHREE(selectionTHREE)
        selectionTHREE = killcommasselectionTHREE(selectionTHREE)
        memberID = ''.join(memberID)
        mylist =[memberID, selection, selectionTWO, selectionTHREE]
        
        T1ytdlatest = mylist[1]
        T2ytdlatest = mylist[2]
        T3ytdlatest = mylist[3]
        
       
        print (mylist, "this is mylist,")
        print(memberID, "this is memberID")
        
        
        UpdateInfo2(db,cursor)
        
        #print("Update SUCCESSFULL")
        
        order_ytd = SelectfromDB(db,cursor)
        #print(order_ytd, "this is the list T1ytd, T2ytd, T3ytd from database")
        T1ytd=eval(order_ytd[0][0])
        T2ytd=eval(order_ytd[0][1])
        T3ytd=eval(order_ytd[0][2])
        
        
        dropped,added,nochange = deltacalculate (T1ytd,T2ytd,T3ytd,T1ytdlatest,T2ytdlatest,T3ytdlatest)
        
        
        
        drop_cnt,dropped = dropcounter(dropped,added)
        add_cnt,added = addcounter(dropped, added)
        nochange_cnt = nochangecounter(nochange)
        
        print (drop_cnt, "this is the drop count")
        print (add_cnt, "this is the add count")
        
        #The following relate to the management of the activity libre registration. They provide the feed
        #for the confirmpurchase() form below. Notice that it was necessary to calculate the total euro
        #value of the basket (not just the delta) for use in determining if the act libre registration fee
        #should be added to or subtracted from the total DELTA value of the basket.
        
        mylist_DUPLICATE = mylist[:]  #!!!!!!!!!!!!!!!!!!!
        # NOTE ON ABOVE - duplicate of mylist needed for use with UpdateInfo1(db,cursor) function
        # THIS IS BECAUSE mylist gets destroyed by use of euro_activityCnt(mylist,total_euro=0,activityCount=0)
        # immediately. It will not therefore be available for use with UpdateInfo1(de,cursor) which is used at
        # the bottom to update registrations with T1ytd, T2ytd and T3ytd
        
        db,cursor=connectDB() 
        total_euro,activityCount,count = euro_activityCnt(mylist)
        print(total_euro, "this is total euro", activityCount, "this is total activity count")  
        
    #--------------------Now proceeding to the printout of the delta basket----------------------
        month, day, year = frenchdate()
        
        Select_Enrol_Status =Select_Enrol_Status(db,cursor)
        Enrol_Status = Select_Enrol_Status[0][0]        
    
        currentyear = datetime.datetime.now().year
        JuniorCheck = JuniorCheck(db,cursor)
        naissance = JuniorCheck[0][0]
        print(naissance, "this is naissance")
        Enroll = SelectEnroll(db,cursor)
        Enroll_adult = Enroll[0][0]
        Enroll_junior = Enroll[0][1]
        print(Enroll_adult, Enroll_junior, "adult and junior enroll")
        ALPAID_ytd = SelectALPAID_ytd(db,cursor)# ALPAID_ytd is the 1/0 value of the column which describes on or off
        ALPAID_ytd =ALPAID_ytd[0][0]# always be careful when you recover a variable from the function
        #in this case you need the [0][0] to pick out the value. Always best to print the returned value and
        #take a look at the list. This will  telll you if you have to use a [0][0] approach to get the value
        print(ALPAID_ytd, "ALPAID_ytd")
    
        activity_libre = SelectActivityLibre(db,cursor) #This getsyou the price of activity libre
        activity_libre = activity_libre[0][0]
        print(activity_libre, "activity_libre")
        
                       
        
        db,cursor=connectDB()
        
        mylist = mylist_DUPLICATE # this is the original mylist
        OrderProfile = OrderProfiler(mylist,db,cursor) #order profile describe the order in terms on 1/0 's
        # its just a list of 1's and 0's. NOTE we are talking about the FINAL order, not the DELTA order.
        
        status = StatusFinder (OrderProfile) # The above list is fed into this function, STATUS. STATUS looks
        #at the list of 1's and 0's and classifies the order into one of 3 possible types - PAID, MIXED or FREE.
        #  mixed (0), activity libre only(1) or paid only(2). This feeds into confirmpurchase() below which 
        # prints out a table of the delta sale and also indicats if the customer has to pay for activity libre
        # of gets if for free. See 
        mylist = mylist_DUPLICATE
        print(mylist,"this is my list just before confirmpurchase() runs")
        print(memberID, "this is memberID just before table")
        db,cursor=connectDB()        
        person= PersonInfo(db,cursor)
        civilites = person[0][0]
        Nom = person[0][1]
        Prenom = person[0][2]
        Adresse = person[0][3]
        ZIP = person[0][4]
        Ville = person[0][5]
       
        
        print(Nom, "this is nom of person")
        Delta_euro_total,SwitchOff,SwitchOn = confirmpurchase() # for receipt printout
    
            
        
       
        print(Delta_euro_total, "Delta_Euro Total")  
        
        
       
        
        print (ALPAID_ytd, "this is ALPAID_YTD at end ")
        print (status, "this is STATUS at end")
        
        
        
        #this updates the registration table for T1ytd,T2ytd,T3ytd - using the  values of T1ytdlatest,  T2ytdlatest
        #Remember we use the difference between the T1ytd and the TIytdlatest to calculate the DELTA value
        #of the order. IE the current incremental purchase which is the diference between these values. 
        print(mylist,"this is my list at the end of action_OrderFormTWO.cgi")
        
        #UpdateInfo1(db,cursor) 
        
        
      
        
        
        
        
        htmlTail()
    except:
        cgi.print_exception()

Open in new window


PAGE 3 CODE
#!C:\Python34\python.exe
import cgi
#import cgitb
import cgitb
cgitb.enable()
import mysql.connector as conn
import collections
import datetime
def htmlTop():
    print("""Content-type:text/html\n\n
        <!DOCTYPE html>
        <html lang="en">
            <head>
                <meta charset="UTF-8">
                <title> My Server-side template</title>
                <link href="style.css" rel="stylesheet" type="text/css">

                <script>var __adobewebfontsappname__="dreamweaver"</script>
                <script src="http://use.edgefonts.net/source-sans-pro:n2,i2,n3,i3,n4,i4,n6,i6,n7,i7,n9,i9:default;source-serif-pro:n4:default.js" type="text/javascript"></script>
        </head>
        <body>""")

def htmlTail():
    print(""" its done</body>
        </html>""")

def getData():
    formData = cgi.FieldStorage()
    mylist = formData.getlist('mylist')
    return mylist


def connectDB():
    db=conn.connect(host='localhost' ,user='root' ,passwd='844cheminduplan' ,db='office')
    cursor = db.cursor()
    return db, cursor 

def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest='{0}', T2ytdlatest='{1}', T3ytdlatest='{2}'
       WHERE memberID={3}
    """.format(mylist[1], mylist[2], mylist[3],mylist[0]))
    db.commit()
    db.close 
    

    
#def UpdateInfo1(db,cursor):#see note at bottom of page  on use of mylist_DUPLICATE
    #cursor.execute ("""
       #UPDATE registrations
       #SET  T1ytd='{0}', T2ytd='{1}', T3ytd='{2}'
       #WHERE memberID={3}
    #""".format(mylist[1], mylist[2], mylist[3],mylist[0]))
    #db.commit()
    #db.close
    
def UpdateInfo1(db,cursor):#see note at bottom of page  on use of mylist_DUPLICATE
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytd='{0}', T2ytd='{1}', T3ytd='{2}'
       WHERE memberID={3}
    """.format(mylist[0], mylist[1], mylist[2], memberID))
    db.commit()
    db.close

    
#def deleterow(db,cursor):
    #cursor.execute(""" 
    #DELETE from registrations_copy
    #WHERE memberID={0}
    #""".format(mylist[0]))
    #db.commit()
    #db.close
    
def deleterow(db,cursor):
    cursor.execute(""" 
    DELETE from registrations_copy
    WHERE memberID={0}
    """.format(memberID))
    db.commit()
    db.close    

def insertrow(db,cursor):
    cursor.execute("""
    INSERT INTO registrations_copy
    SELECT * 
    FROM registrations
    WHERE memberID={0}
    """.format(memberID))
    db.commit()
    db.close
    
def InsertTransactions(db,cursor):
    strSQL = "insert into transactions(memberID, YTDPurchases, lastpurchase) values ({0}, {1}, {2})".format(memberID, Delta_euro_total, Delta_euro_total )
    cursor.execute(strSQL)
    db.commit()     
    db.close() 
    
#def InsertTransactions(db,cursor):#this works just as well as one above
    #cursor.execute("""
        #INSERT into transactions (memberID)
        #VALUES ('{0}')
        #""".format(memberID))
        ##VALUES memberID = 'memberID'
    #db.commit()
    #db.close
    

    
def UpdateTransactions(db,cursor):
    db,cursor=connectDB()
    cursor.execute ("""
       UPDATE transactions
       SET  deductions = {0}, bills = {1}, ChequesPaid = {2}, owed ={3}
       WHERE memberID={4}
    """.format(deductions, bills, ChequesPaid, owed, memberID))
    db.commit()
    db.close  
    

    
    
    
    
    
    
    
    
#def Turn_On_Alibe(db,cursor):#used above for turning on the ALPAID_ytd switch
    #db,cursor=connectDB()
    #cursor.execute ("""
       #UPDATE registrations
       #SET  ALPAID_ytd=1
       #WHERE memberID={0}
    #""".format(mylist[0]))
    #db.commit()
    #db.close
    
    
    
    
    
    
    
def transactioncheck(db,cursor):#This checks to see if there exists a record for memberID
    cursor.execute("""SELECT COUNT(*) from transactions where memberID='%s'"""
    %(memberID))
    result=cursor.fetchone()
    return result # see below as to how this is used

def SelectfromDB(db,cursor):
    cursor.execute("""select YTDPurchases from transactions WHERE memberID = "%s" """
    %(memberID)) 
    YTDpurchases=cursor.fetchone()
    return YTDpurchases

def SelectfromTransactions(db,cursor):
    cursor.execute("""select Deductions, ChequesPaid, bills, owed from transactions WHERE memberID = "%s" """
    %(memberID)) 
    transactions=cursor.fetchall()
    return transactions


def SelectActivityLibre(db,cursor): #picks out the value activity libre registration charge form fees table
    cursor.execute ("""SELECT activity_libre from fees""")
    activity_libre=cursor.fetchall()
    return activity_libre

def page():
    
    print("<div id='wrapper'> ")
    
    #HEADER
    print("<header>")
    print("<h2 id='stargazer'>") 
    print("ABAC APPLICATION")
    print("</h2>")
    print("<nav>")
    print("<ul>")
    print("<li>")
    print("<a href='#'>")
    print("ABOUT")
    print("</a>")
    print("</li>")
    print("<li>")
    print("<a href='#'>")
    print("IMAGES")
    print("</a>")
    print("<li>")
    print("<a href='#'>")
    print("ARTICLES")
    print("</a>")
    print("<li>")
    print("</ul>")
    print("</nav>")
    print("</header>")
    
    
    # BREAK LINE
    print("<div id='more'>")
    print("<hr>")
    print("</div>")
    
    
    print("<div id='content1'>")
    
    print("<p>")
    print("<h2 id='stargazer'>{civilites} {Prenom} {Nom}</th>".format(civilites = civilites, Prenom = Prenom, Nom = Nom))
    print("</p>")
    
    #print("<p>")
    #print("&nbsp;")
    #print("</p>")
    #print("<p>")
    #print("&nbsp;")
    #print("</p>") 
    print("<p>")
    print("{Adresse}".format(Adresse = Adresse))
    print("</p>")
    #print("<p>")
    #print("Avenue de Hespérides")
    #print("</p>")    
    #print("<p>")
    #print("09400 CANNES")
    #print("</p>")    
    print("<p>")
    print("{ZIP} {Ville}".format(ZIP = ZIP, Ville = Ville))
    print("</p>")       
    print("<p>")
    print("&nbsp;")
    print("</p>") 
    print("<p>")
    print("&nbsp;")
    print("</p>")   
    
    # end of address section
    
    print("<p>")
    print("<table width='683' border='1' align='center'>")           
    print("<tbody>")        
    print("<tr>")
    print("<td colspan='3' align='left'> ")
    print("<pre>")
    print("PRESTATIONS")
    print("</pre>")
    print("</td>")
    print("</tr>")
    #headers
    print("<tr>")
    print("<td width='247' align='left' valign='middle'>")
    print("<pre>")
    print("Activity")
    print("</pre>")
    print("</td>")
    print("<td width='104' align='left'>")
    print("<pre>")
    print("Trimesters")
    print("</pre>")
    print("</td>")
    print("<td width='156' align='left'>")
    print("<pre>")
    print("A payer")  
    print("</pre>")
    print("</td>")
    print("</tr>")
    
    #values
    
    Delta_euro_total = 0
    
    if len(add_cnt) != 0:
        for each in add_cnt:
            print("<tr>")
            courseNumber = each
            print(courseNumber,"this is coursenumber")
            activityinfo(db,cursor,courseNumber)
            activitydata = activityinfo(db,cursor,courseNumber)
            print(activitydata, "this is activitydata!!!!!")
            #print("<td align=center>{0}</td>".format(activitydata[0][0]))
            print("<td align=center>{0}</td>".format(activitydata[0][1]))
            print("<td align=center>{0}</td>".format(add_cnt[each]))
            if add_cnt[each] == 3:
                print("<td align=center>{0}</td>".format(activitydata[0][2])) #using tariff36 pricing
                Delta_euro_total = Delta_euro_total + activitydata[0][3]
            else:
                print("<td align=center>{0}</td>".format(add_cnt[each]*activitydata[0][2]))
                Delta_euro_total = Delta_euro_total + add_cnt[each]*activitydata[0][2]
            print("</tr>")
            
            
    if len(drop_cnt) != 0:
        for each in drop_cnt:
            print("<tr>")
            courseNumber = each
            activityinfo(db,cursor,courseNumber)
            activitydata = activityinfo(db,cursor,courseNumber)
            #print("<td align=center>{0}</td>".format(activitydata[0][0]))
            print("<td align=center>{0}</td>".format(activitydata[0][1]))
            print("<td align=center>{0}</td>".format(-drop_cnt[each]))            
            
            if drop_cnt[each] == 3:
                print("<td align=center>{0}</td>".format(-activitydata[0][3])) #using tariff36 pricing
                Delta_euro_total = Delta_euro_total - activitydata[0][3]
                
            else:
                print("<td align=center>{0}</td>".format(-drop_cnt[each]*activitydata[0][2]))
                Delta_euro_total = Delta_euro_total - drop_cnt[each]*activitydata[0][2]
                
            print("</tr>")
            
            
            
            
    if ALPAID_ytd != 1 and status == 1: #free only
        print("<tr>")
        print("<td colspan=2 scope=row align=center>Registration Activite Libre</td>")
        print("<td align=center>{0}</td>".format(activity_libre))
        Delta_euro_total = Delta_euro_total + activity_libre
        #Turn_On_Alibe(db,cursor)#turns on the switch ALPAID_ytd       
        print("</tr>")            
            
            
     
    elif ALPAID_ytd != 0 and status == 0: #mixed
        print("<tr>")
        print("<td colspan=2 scope=row align=center>Reimbourse Registration Activite Libre</td>")
        print("<td align=center>{0}</td>".format(-activity_libre)) 
        Delta_euro_total = Delta_euro_total - activity_libre
        #Turn_Off_Alibe(db,cursor)#turns off the switch ALPAID_ytd
        print("</tr>")       
    
           
        
    elif ALPAID_ytd != 0 and status == 2: #paid only
        print("<tr>")
        print("<td colspan=2 scope=row align=center>Reimbourse Registration Activite Libre</td>")
        print("<td align=center>{0}</td>".format(-activity_libre)) 
        Delta_euro_total = Delta_euro_total - activity_libre
        #Turn_Off_Alibe(db,cursor)#turns off the switch ALPAID_ytd
        print("</tr>")
        
        
    if (currentyear - naissance) < 17 and Enrol_Status == 0:
        print("<tr>")
        print("<td colspan=2 scope=row align=center>Tarif de L'adhesion (Junior)</td>")
        Delta_euro_total = Delta_euro_total + Enroll_junior
        #UpdateEnrolStatus(db,cursor)
        print("<td align=center>{0}</td>".format(Enroll_junior)) 
        print("</tr>")
        
    elif Enrol_Status == 0 :
        print("<tr>")
        print("<td colspan=2 scope=row align=center>Tarif de L'adhesion (Adult)</td>")
        Delta_euro_total = Delta_euro_total + Enroll_adult
        #UpdateEnrolStatus(db,cursor)
        print("<td align=center>{0}</td>".format(Enroll_adult)) 
        print("</tr>")       
    
    #print("<tr>")
    #print("<td>")
    #print("&nbsp;")
    #print("</td>")
    #print("<td>")
    #print("&nbsp;")
    #print("</td>")    
    #print("<td>")
    #print("&nbsp;")
    #print("</td>")    
    #print("</tr>")
    
    
    
    
    
    
    print("</tbody>")
    print("</table>")
    
    
    #spaces
    
    print("</p>")
    print("<p>")
    print("&nbsp;")
    print("</p>")
    print("<p>")
    print("&nbsp;")
    print("</p>")      
    print("<p>")
    print("&nbsp;")
    print("</p>")   
    
    # PAIEMENT TABLE
    print("<table width='529' border='1'align='center'>")
    print("<tbody>")
    print("<tr align='left'>")
    print("<td colspan='3'>")
    print("<pre>")
    print("PAIEMENT")
    print("</pre>")
    print("</td>")
    print("</tr>")
    print("<tr align='left'>")
    print("<td valign='middle'>")
    print("&nbsp;")
    print("</td>")
    print("<td valign='middle'>")
    print("&nbsp;")
    print("</td>")    
    print("<tr>")
    print("</tbody>")
    print("</table>")
    #spaces
    print("<p>")
    print("&nbsp;")
    print("</p>")
 
    print("<p>")
    print("&nbsp;")
    print("</p>")
    # Program de vos activities table
    print("<table width='800' border='1' align='center'>")
    print("<tbody>")
    print("<tr align='left'>")
    
    print("<td colspan='7'>")
    print("<pre>")
    print("PROGRAM DE VOS ACTIVITIES")
    print("</pre>")
    print("</td>")
    
    print("</tr>")
    print("<tr align='left'>")
    
    print("<td width='87'>")
    print("<pre>")
    print("Jour")
    print("</pre>")
    print("</td>")
    
    print("<td width='77'>")
    print("<pre>")
    print("Heures")
    print("</pre>")
    print("</td>")    
    
    
    print("<td>")
    print("<pre>")
    print("Activite")
    print("</pre>")
    print("</td>")
    
    print("<td>")
    print("<pre>")
    print("Animateur")
    print("</pre>")
    print("</td>")    
    
    print("<td>")
    print("<pre>")
    print("Trim 1")
    print("</pre>")
    print("</td>")
    
    print("<td>")
    print("<pre>")
    print("Trim 2")
    print("</pre>")
    print("</td>")    
    
    print("<td>")
    print("<pre>")
    print("Trim 3")
    print("</pre>")
    print("</td>")    
    
    print("</tr>")
    
    
    print("<tr align='left'>")
    
    print("<td>")
    print("&nbsp;")
    print("</td>")
    
    print("<td>")
    print("&nbsp;")
    print("</td>")    
    
    
    
    print("<td width='276'>")
    print("&nbsp;")
    print("</td>")
    
    print("<td width='161'>")
    print("&nbsp;")
    print("</td>") 
        
    print("<td width='51'>")
    print("&nbsp;")
    print("</td>")    
    
    print("<td width='51'>")
    print("&nbsp;")
    print("</td>")  
                
    print("<td width='51'>")
    print("&nbsp;")
    print("</td>")    
    
    print("</tr>")
    print("</tbody>")
    print("</table>")

    print("<p>")
    print("&nbsp;")
    print("</p>")

    print("<p>")
    print("&nbsp;")
    print("</p>")    
        
    print("<p>")
    print("&nbsp;")
    print("</p>")  
    
    print("<p>")
    print("&nbsp;")
    print("</p>")    

    print("</div>")
    print("</div>")


def PersonInfo(db,cursor): # this to grab info on person whose order is being processed
    cursor.execute("""select civilites, Nom, Prenom, Adresse, ZIP, Ville from members2 WHERE memberID = "%s" """
    %(memberID)) 
    person=cursor.fetchall()
    return person

def activityinfo(db,cursor,courseNumber):
    cursor.execute("""select courseNumber,Activity, tariffstwelve, tariffsthirtysix from activities WHERE courseNumber = "%s" """
    %(courseNumber)) 
    activityinfo=cursor.fetchall()
    return activityinfo


  



    
#main program
if __name__== "__main__":
    try:
        htmlTop()
        print("hello this is the form")
        db,cursor=connectDB()
        activitydata = activityinfo(db,cursor,8)
        print(activitydata, "this is activitydata")
        
        print(activitydata[0][1])
        
        
        db,cursor=connectDB()
        
        
        
        
        form = cgi.FieldStorage()
        bills = eval(form.getvalue('bills'))
        deductions = eval(form.getvalue('deductions'))
        ChequesPaid = eval(form.getvalue('ChequesPaid'))
        Delta_euro_total = eval(form.getvalue('Delta_euro_total'))
        owed = Delta_euro_total - deductions - bills - ChequesPaid
        mylist=form.getvalue('mylist')
        print(mylist, "the first mylist")
        memberID=eval(form.getvalue('memberID'))
        print(memberID, "this is memberID")
        orderlist = mylist[0][1]
        currentyear = mylist[1]
        naissance = mylist[2]
        Enrol_Status = mylist[3]
        ALPAID_ytd = mylist[4]
        status = mylist[5]
        #add_count = mylist[6]
        #drop_count = mylist[7]
        order = eval(mylist[0])
        T1ytd= order[0]
        print(T1ytd, "t1ytd")
        T2ytd= order[1]
        print(T2ytd, "t2ytd")
        T3ytd= order[2]
        print(T3ytd, "t3ytd")
        add_cnt = form.getvalue('add_cnt')
        print(add_cnt, "this is the add_cnt")
        drop_cnt = form.getvalue('drop_cnt')
        print(drop_cnt, "this is the drop_cnt")

        print(Delta_euro_total, "delta_euro_total")
        print(currentyear, "currentyear")
        print(naissance, "naissance")
        print(Enrol_Status, "Enrol_Status")
        print(mylist, "mylist")
        print(ALPAID_ytd, "ALPAID_ytd")
        print(status, "status")
        print(memberID, "memberID")
        print(order, "this is order")
        print(T1ytd, "this is T1ytd")
        print(T2ytd, "this is T2ytd")
        print(T3ytd, "this is T3ytd")
        print(deductions, "eductions")
        print(ChequesPaid, "chequespaid")
        print(bills, "bills")
        
        
        
        
        #BELOW IS WORK TO CAPTURE THE TRANSACTIONS TABLE DATA FOR UPDATING 
        #NOTE THE UPDATING IS ON A YTD BASIS WHICH IS THE SUM OF CURRENT TRANSACTION PLUS LAST VALUE FROM TABLE
            
        SelectfromTransactions(db,cursor)
        transactions = SelectfromTransactions(db,cursor)
        deductions_last = transactions[0][0]
        deductions = deductions + deductions_last
        ChequesPaid_last = transactions[0][1]
        ChequesPaid = ChequesPaid_last + ChequesPaid
        bills_last = transactions[0][2]
        bills = bills + bills_last
        owed_last = transactions[0][3]
        owed = owed_last + owed
        
        UpdateTransactions(db,cursor)  
        
        # BELOW IS EXTRA INFO NEEDED FOR THE DYNAMIC PAGE TABLE
        db,cursor=connectDB()        
        person= PersonInfo(db,cursor)
        civilites = person[0][0]
        Nom = person[0][1]
        Prenom = person[0][2]
        Adresse = person[0][3]
        ZIP = person[0][4]
        Ville = person[0][5] 
        
        activity_libre = SelectActivityLibre(db,cursor) #This gets you the price of activity libre
        activity_libre = activity_libre[0][0]
        print(activity_libre, "activity_libre")        
        
        
        
        
        
        
        
        page()
                  
            
            

        
        
        htmlTail()
    except:
        cgi.print_exception()

Open in new window

counter1.jpg
counter2.jpg
counter3.jpg
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are   right Marc - its a bit of a nonsense trying to pass a 'function' through to page 3 and then expecting it to run there without the proper definition of what it is !!

aikimark,  I think you have put me on the right track here.  In page 1
def deltacalculate (T1ytd,T2ytd,T3ytd,T1ytdlatest,T2ytdlatest,T3ytdlatest):  gives me variables dropped and added - which, when fed into functions  def dropcounter(dropped, added): and
def addcounter(dropped, added): gave drop_cnt and add_cnt.

So, what I need to pass over to page 3 are the variable values  for dropped and added - which for the example we are looking at would be two lists
added = [7,8,7,8,9,10,7,8] and dropped = []. I then feed these into the  functions
def dropcounter(dropped, added): and def addcounter(dropped, added): - which I should add to Page 3. These provide me with add_cnt and drop_cnt - exactly as in page I.

Hopefully, problem solved - maybe apart from security aikimark?

I'll leave it until tomorrow before trying - just in case there is an obvious mistake in my thinking.  

Thank you all for clearing up my confusion !!!!
Encryption and some serialization would probably take care of the basic security.  You could also throw in some hashing if you absolutely need to detect hacking activities.
If passing the string isn't enough, you might need to use Pickle to serialize/deserialize objects and data.
Brady, pepr, aikimark,

have reworked the code and passed through the two variables added and dropped. Used these in the recreation of add_cnt and drop_cnt on the page. That works.  

However, I now have another subtle problem (unconnected with above) which needs an expert eye. Its bounded, so hopefully easily solvable ... by you of  course.

I will close out this question, but will create another question regarding new problem - hopefully you can take a look.

Thanks to you all.