我想问您一些建议,以加快我的代码的速度。我知道您会看到很多错误,但是我需要您的知识和帮助,问题出在哪里以及如何改进此代码。
背景-创建什么应用程序:
{1:'@ 5C \ Qopen @',2:'20386239',3:'3000133215',4:'RA',5:无, 6:'Vendor2',7:'IM45',8:'@FR \ QNot due @',9:无,10:无,11: 'E1',12:'DNS',13:datetime.datetime(2019,12,27,0,0),14: datetime.datetime(2019,12,26,0,0),15:-21501,16:'GBP',17: -21501,18:'GBP',19:datetime.datetime(2019,12,26,0,0),20:datetime.datetime(2020,2,9,0,0)}
{2:'@ 5C \ Qopen @',2:'20386239', 3:'3000133215',4:'RA',5:无,6:'Vendor1',7:'IM45',8: '@FR \ QNot due @',9:无,10:无,11:'E1',12:'DNS',13: datetime.datetime(2019,12,27,0,0),14:datetime.datetime(2019,12, 26,0,0),15:-21501,16:'GBP',17:-21501,18:'GBP',19: datetime.datetime(2019,12,26,0,0),20:datetime.datetime(2020,2, 9,0,0)}
{3:'@ 5C \ Qopen @',2:'20386239', 3:'3000133215',4:'RA',5:无,6:'Vendor1',7:'IM45',8: '@FR \ QNot due @',9:无,10:无,11:'E1',12:'DNS',13: datetime.datetime(2019,12,27,0,0),14:datetime.datetime(2019,12, 26,0,0),15:-21501,16:'EUR',17:-21501,18:'GBP',19: datetime.datetime(2019,12,26,0,0),20:datetime.datetime(2020,2, 9,0,0)}
您知道我该如何改进吗? 谢谢
next_row2 = 1
numerkolumny = 1
nastepny = 1
numer_vendora = 1
ilosc_gbp = 0
ilosc_inne = 0
linijkadanych = {}
lista_vendorow = {}
for zmienna2 in progressbar.progressbar(assets2, redirect_stdout=True):
for iteracja in assets2:
if assets2[zmienna2][6] not in lista_vendorow.values():
if nastepny < len(assets2):
if assets2[zmienna2][6] == assets2[nastepny+1][6]:
if assets2[nastepny+1][16] == "GBP": # JESLI ZNALAZLES GBP, POLICZ DO GBP
ilosc_gbp = ilosc_gbp + 1
nastepny = nastepny + 1
else: # JESLI ZNALAZLES INNA WALUTE, POLICZ DO INNEJWALUTY
ilosc_inne = ilosc_inne + 1
nastepny = nastepny + 1
else:
nastepny = nastepny + 1
if nastepny >= len(assets2): # JESLI PRZEITEROWALES PRZEZ WSZYSTKIE WIERSZE, OBLICZ WYNIK
suma_walut = ilosc_gbp + ilosc_inne # SUMUJ WSZYSTKIE WALUTY
# JESLI ZNAJDZIE ODCHYLELNIA - RAPORTUJ!
if (suma_walut != ilosc_gbp) and (suma_walut != ilosc_inne):
for waluty in assets2: # nr wiersza
for waluty2 in assets2[waluty]: # nr kolumny
if assets2[waluty][6] == assets2[zmienna2][6]:
if ilosc_gbp > ilosc_inne:
result_tab.cell(column=17, row=waluty+1, value="Waluta other than GBP. Check!").font = style_blad_bold
else:
result_tab.cell(column=17, row=waluty+1, value="Other currencies between GBP!. Check!").font = style_blad_bold
lista_vendorow[numer_vendora] = assets2[zmienna2][6]
ilosc_gbp = 0 # ZERUJ ZMIENNE, LICZYMY NOWEGO VENDORA
ilosc_inne = 0 # ZERUJ ZMIENNE, LICZYMY NOWEGO VENDORA
nastepny = 1 # ZERUJ ZMIENNE, LICZYMY NOWEGO VENDORA
numer_vendora = numer_vendora + 1