Ich bin momentan dabei meinen code u.a. zu vereinfachen und eines der Hauptprobleme ist, dass sich gewisse Strukturen wiederholen. Deshalb will ich eine Funktion schreiben, die ich dann z.B. spaeter abhaengig von anderen Parametern ausfuehern kann.
Code: Alles auswählen
def main():
Qcont, A1, Around, nameiso, abu, qdivbya, abu2, information = readcontaminationfile()
cavmaxCSS, cavmaxreal, factor = readcavmaxfile()
betaS, geff, Lambda, phi, Qin, A, E, Ein, minimumf, maximumf, Vebitmax, check2, check1, check3, check4, \
number, minnumber, maxnumber, diffqa0, cavlist, combo = getInputs(A1, Around, nameiso, Qcont, factor)
alarm(cavlist, cavmaxCSS, number)
decision(betaS, geff, Lambda, phi, Qin, A, E, Ein, minimumf, maximumf, Vebitmax, check2, check1, check3, check4,\
number, minnumber, maxnumber, cavlist, factor, cavmaxCSS, cavmaxreal)
clickrow(Qcont, A1, nameiso, abu, qdivbya, abu2, information, A, diffqa0, check3, check4, factor, \
betaS, geff, Lambda, phi, minimumf, maximumf, cavmaxreal, combo)
def clickrow(Qcont, A1, nameiso, abu, qdivbya, abu2, information, A, diffqa0, check3, check4, factor, betaS, geff, Lambda, phi,\
minimumf, maximumf, cavmaxreal, combo):
if combo == "all":
liste = []
for a,b,c,d,e in zip(qdivbya,Qcont,nameiso, A1,abu2):
diffqa = abs(beamqdivbya - a )
diffqaoverqa = float(diffqa)/float(Qchosen)* A
if diffqa < diffqa0:
# here another if structure, so that either shows only stable isotopes or all the isotopes
liste.append(a)
len(liste)
table1.setCellText(len(liste) - 1 , 0, str(c))
table1.setCellText(len(liste) - 1 , 1, str(b))
table1.setCellText(len(liste) - 1 , 2, str(d))
table1.setCellText(len(liste) - 1 , 3, str(a))
table1.setCellText(len(liste) - 1 , 4, str(diffqaoverqa))
table1.setCellText(len(liste) - 1 , 5, str(e))
# something is needed to update the contaminationlist in case there is no contamination! otherwise the old contamination from another row you pressed before
if combo == "stable":
liste = []
for a,b,c,d,e in zip(qdivbya,Qcont,nameiso, A1,abu2):
if float(e) > 0:
diffqa = abs(beamqdivbya - a )
diffqaoverqa = float(diffqa)/float(Qchosen)* A
if diffqa < diffqa0:
# here another if structure, so that either shows only stable isotopes or all the isotopes
liste.append(a)
len(liste)
table1.setCellText(len(liste) - 1 , 0, str(c))
table1.setCellText(len(liste) - 1 , 1, str(b))
table1.setCellText(len(liste) - 1 , 2, str(d))
table1.setCellText(len(liste) - 1 , 3, str(a))
table1.setCellText(len(liste) - 1 , 4, str(diffqaoverqa))
table1.setCellText(len(liste) - 1 , 5, str(e))
if __name__ == '__main__': main()
Ich habe natuerlich noch andere Funktionen in meiner main-Funktion, aber den Kontext reinzukopieren, haette horrende Ausmasse- so extrem effizient wie ich meinen code geschrieben habe;)
Ich wuerde gern sowas in der Art durchfuehren, habe aber keine Ahnung wie:(
Code: Alles auswählen
def main():
Qcont, A1, Around, nameiso, abu, qdivbya, abu2, information = readcontaminationfile()
cavmaxCSS, cavmaxreal, factor = readcavmaxfile()
betaS, geff, Lambda, phi, Qin, A, E, Ein, minimumf, maximumf, Vebitmax, check2, check1, check3, check4, \
number, minnumber, maxnumber, diffqa0, cavlist, combo = getInputs(A1, Around, nameiso, Qcont, factor)
alarm(cavlist, cavmaxCSS, number)
decision(betaS, geff, Lambda, phi, Qin, A, E, Ein, minimumf, maximumf, Vebitmax, check2, check1, check3, check4,\
number, minnumber, maxnumber, cavlist, factor, cavmaxCSS, cavmaxreal)
clickrow(Qcont, A1, nameiso, abu, qdivbya, abu2, information, A, diffqa0, check3, check4, factor, \
betaS, geff, Lambda, phi, minimumf, maximumf, cavmaxreal, combo)
def printer(a,b,c,d,e,beamqdivbya, Qchosen, A):
diffqa = abs(beamqdivbya - a )
diffqaoverqa = float(diffqa)/float(Qchosen)* A
if diffqa < diffqa0:
liste.append(a)
len(liste)
table1.setCellText(len(liste) - 1 , 0, str(c))
table1.setCellText(len(liste) - 1 , 1, str(b))
table1.setCellText(len(liste) - 1 , 2, str(d))
table1.setCellText(len(liste) - 1 , 3, str(a))
table1.setCellText(len(liste) - 1 , 4, str(diffqaoverqa))
table1.setCellText(len(liste) - 1 , 5, str(e))
def clickrow(Qcont, A1, nameiso, abu, qdivbya, abu2, information, A, diffqa0, check3, check4, factor, betaS, geff, Lambda, phi,\
minimumf, maximumf, cavmaxreal, combo):
if combo == "all":
liste = []
for a,b,c,d,e in zip(qdivbya,Qcont,nameiso, A1,abu2):
printer(a, b, c, d, e, beamqdivbya, Qchosen, A)
if combo == "stable":
liste = []
for a,b,c,d,e in zip(qdivbya,Qcont,nameiso, A1,abu2):
if float(e) > 0:
printer(a, b, c, d, e, beamqdivbya, Qchosen, A)
if __name__ == '__main__': main()Liebe Gruesse,
Peter
