Parameter in verschiedenen Umgebungen
Verfasst: Donnerstag 22. August 2013, 14:59
NameError: global name 'stable' is not defined
Das ist der error, den ich gerade bekomme. ich musste ein paar aenderungen an meinem code durchfuehren, weswegen ich jetzt zwei files einlese, um dadurch die geschwindigkeit zu steigern, da eines kuerzer ist.
eines besitzt den namen
Q_A_Sym_ME_A_abu_stable
das andere den namen
Q_A_Sym_ME_A_abu_unstable
Das eine enthaelt nur die stabilen, das andere auch die instabilen elemente.
beide haben das gleiche format, die gleiche information und sind gleich aufgebaut(das eine hat mehr elemente und das andere weniger) um den code etwas zu kuerzen, wollte ich nun dies machen:
ich bin als erstes nicht sicher, wie ich zugriff auf ein wort habe, das unter anfuehrungszeichen steht
infile = open("C:\Python27\Q_A_Sym_ME_A_abu_" + "property" + ".txt",'r')
Ausserdem habe ich wieder das Problem, dass stable und unstable keine globalen Namen sind.
Das ist der error, den ich gerade bekomme. ich musste ein paar aenderungen an meinem code durchfuehren, weswegen ich jetzt zwei files einlese, um dadurch die geschwindigkeit zu steigern, da eines kuerzer ist.
eines besitzt den namen
Q_A_Sym_ME_A_abu_stable
das andere den namen
Q_A_Sym_ME_A_abu_unstable
Das eine enthaelt nur die stabilen, das andere auch die instabilen elemente.
beide haben das gleiche format, die gleiche information und sind gleich aufgebaut(das eine hat mehr elemente und das andere weniger) um den code etwas zu kuerzen, wollte ich nun dies machen:
ich bin als erstes nicht sicher, wie ich zugriff auf ein wort habe, das unter anfuehrungszeichen steht
infile = open("C:\Python27\Q_A_Sym_ME_A_abu_" + "property" + ".txt",'r')
Ausserdem habe ich wieder das Problem, dass stable und unstable keine globalen Namen sind.
Code: Alles auswählen
def readcontaminationfile(property):
#can be added if you want to change rhe file fname = raw_input("Please enter a filename.txt ")
infile = open("C:\Python27\Q_A_Sym_ME_A_abu_" + "property" + ".txt",'r')
info_property = (column.strip().split() for column in infile)
x_property = zip(*info)
Qcont_property = map(int,x[0])
Around_property = map(int, x[1])
A1_property = map(float,x[4])
nameiso_property = x[2]
abu_property = x[5]
qdivbya_property = [float(b)/float(m) for b,m in zip(Qcont,A1)]
abu2_property = map(float, abu)
information_property = zip(qdivbya,Qcont,A1,nameiso,abu2)
return Qcont_property, A1_property, Around_property, nameiso_property, abu_property, qdivbya_property, abu2_property, information_property
def main():
Qcont_stable, A1_stable, Around_stable, nameiso_stable, abu_stable, qdivbya_stable, abu2_stable, information_stable = readcontaminationfile(stable)
Qcont_unstable, A1_unstable, Around_unstable, nameiso_unstable, abu_unstable, qdivbya_unstable, abu2_unstable, information_unstable = readcontaminationfile(unstable)
cavmaxCSS, cavmaxreal, factor = readcavmaxfile()
phi, Qin, A, E, diffE, minimumf, maximumf, Vebitmax, check2, check1, check3, check4, checks,\
number, numbers, diffqa0, cavlist, combo = getInputs(A1, Around, nameiso, Qcont, factor)
alarm(cavlist, cavmaxCSS, number)
Qout, fieldout, numberout, Energyout = decision(phi, Qin, A, E, diffE, minimumf, maximumf, Vebitmax, checks, \
number, numbers, cavlist, factor, cavmaxCSS, cavmaxreal)
clickrow(Qcont, A1, nameiso, qdivbya, abu2, information, A, diffqa0, check3, check4, factor,
phi, minimumf, maximumf, cavmaxreal, combo,
Qcont_stable, A1_stable, Around_stable, nameiso_stable, abu_stable, qdivbya_stable, abu2_stable, information_stable,
Qcont_unstable, A1_unstable, Around_unstable, nameiso_unstable, abu_unstable, qdivbya_unstable, abu2_unstable, information_unstable)
def contaminationcalc(property):
result = []
for a,b,c,d,e in zip(qdivbya_property,Qcont_property,nameiso_property, A1_property,abu2_property):
diffqa = abs(beamqdivbya - a )
if diffqa < diffqa0:
diffqaoverqa = float(diffqa)/float(Qchosen)* A
result.append(a)
set_cells(table1, len(result)-1, c, b, d, a, diffqaoverqa, e)
def clickrow(Qcont, A1, nameiso, qdivbya, abu2, information, A, diffqa0, check3, check4, factor, phi, minimumf, maximumf, cavmaxreal, combo,
Qcont_stable, A1_stable, Around_stable, nameiso_stable, abu_stable, qdivbya_stable, abu2_stable, information_stable,
Qcont_unstable, A1_unstable, Around_unstable, nameiso_unstable, abu_unstable, qdivbya_unstable, abu2_unstable, information_unstable):
# Qchosen gets chosen before but this part is not import for here
if combo == "stable":
contaminationcalc(stable)
if combo == "unstable":
contaminationcalc(unstable)
if __name__ == '__main__': main()