poniedziałek, 24 października 2011

more lines == more profit

  def _SortItemizedDataListById_(self, a, b):
    if a.Transaction_Number < b.Transaction_Number:
      return -1
    
    return int(a.Transaction_Number > b.Transaction_Number)


Isn't easyer to fo it using cmp build-in function??

wtorek, 19 lipca 2011

  1. Make sure that there are no duplicates!!!
    select distinct tc.COMPANY_ID, tc.NAME from 
           TAB_TACC_RECHNUNGEN tr,  
           tab_tacc_company tc 
    where tr.COMPANY_ID = tc.COMPANY_ID and 
           UPPER(tc.NAME) like UPPER('%scc%') 
    group by tc.COMPANY_ID, tc.NAME 
    order by tc.NAME
    
    
    tab_tacc_technungen is needed because we need only companies with invoices - but why join and not exist?
    Why distinct and group by?
    tc.company_id is PK of tab_tacc_company - so after elimination of 'join', distinct is not needed any more.

poniedziałek, 18 lipca 2011

piątek, 15 lipca 2011

List to String in Python

  1. Using build in __str__ and str.strip
     if isinstance(tour_id, list):
                tour_id_str = str(tour_id).strip("[]")
    
    

    The fact is that tour_id contains only ints so 'casting' to string have to be done befor using str.join

  2. Using for loop
    tmpCompanyListStr = ""
            for tmpCompany in cid:
                tmpCompanyListStr += "%s, " %(tmpCompany)
            tmpCompanyListStr = tmpCompanyListStr.rstrip(', ')
    
    It is hard to say if author had knowlage about str.join but he was using str.rstrip.