Wie kann ich sicherstellen, dass die Variablen brk1_int_c,brk1_ext_c,brk2_int_c,brk2_ext_c
innerhalb der parseTwoPoleBreakres
in inputList
anstelle der brk1_int_c,brk1_ext_c,brk2_int_c,brk2_ext_c
außerhalb der Funktion aufgerufen werden?Aufrufen von übergeordneten Variablen in Liste
Ich habe Schwierigkeiten mit meiner parseTwoPoleBreakers
Funktion. Ich versuche, eine Liste inputListin in die Funktion einzugeben, so dass ich weiß, wo brk1_int_c, brk1_ext_c, brk2_int_c, brk2_ext_c innerhalb dieser Liste zu platzieren. Ich gebe die Liste in Ordnung ein, aber die brk1_int_c,brk1_ext_c,brk2_int_c,brk2_ext_c
der Variablen werden nicht in inputList
innerhalb meiner parseTwoPoleBreakers
Funktion aufgerufen.
Die Variable I nennen wollen, sind:
brk1_int_c=str(df1['Unnamed: 1'][aRowNum])#starts at row 7,13,19,25,31,37,43,49. addition of 6
brk1_ext_c=str(df1['Unnamed: 2'][aRowNum])
brk2_int_c=str(df1['Unnamed: 1'][bRowNum])
brk2_ext_c=str(df1['Unnamed: 2'][bRowNum])`
, die in der 'parseTwoPoleBreakers' Funktion liegen, sondern
brk1_int_c = '' brk1_ext_c = '' brk2_int_c = '' brk2_ext_c = ''
genannt werden, und als Ergebnis habe ich den Ausgang für unter
print two_pbwmco_a_bString print "breaker id" + str(breakerid)
Ausgangsergebnis:
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id1
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id2
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id3
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id4
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id5
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id6
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id7
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id8
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id9
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id10
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id11
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id12
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id13
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id14
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id15
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id16
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id17
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id18
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id19
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id20
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,,,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,1
breaker id21
Mein Code ist unten:
import pandas as pd
with pd.ExcelFile("C:/Users/original.xlsx",
sheetname=['pnl1 Data ','pnl2 Data','pnl3 Data','pnl4 Data']) as xlsx:
df1 = pd.read_excel(xlsx, 'pnl1 Data ', skiprows=9, parse_cols="B:H", keep_default_na='FALSE', na_values=['NULL'])
df2 = pd.read_excel(xlsx, 'pnl2 Data', skiprows=9, parse_cols="B:H", keep_default_na='FALSE', na_values=['NULL'])
df3 = pd.read_excel(xlsx, 'pnl3 Data', skiprows=9, parse_cols="B:H", keep_default_na='FALSE', na_values=['NULL'])
df4 = pd.read_excel(xlsx, 'pnl4 Data', skiprows=9, parse_cols="B:H", keep_default_na='FALSE', na_values=['NULL'])
# 2. convert data into a single row, in the correct order, and into csv format
df1numOfRows = len(df1.index)
# 2a. you need to look at the breaker table to see what the highest breaker id is and then use the number one higher than that
#fi_breakerTable = open(document,"r")
# 2b. store variables in a list that will be written to csv
breakerid=0
deviceid=0
NULL="NULL"
# 2bc. FDC Feed Braeker "List"
g_int_c=str(df1['Unnamed: 1'][6])
g_ext_c=str(df1['Unnamed: 2'][6])
breakertype="NULL"#should I keep this null or does it equal "FDC Feed Breaker"?
n_int_c=str(df1['Unnamed: 1'][5])
n_ext_c=str(df1['Unnamed: 2'][5])
a_int_c=str(df1['Unnamed: 1'][2])
a_ext_c=str(df1['Unnamed: 2'][2])
b_int_c=str(df1['Unnamed: 1'][3])
b_ext_c=str(df1['Unnamed: 2'][3])
c_int_c=str(df1['Unnamed: 1'][4])
c_ext_c=str(df1['Unnamed: 2'][4])
a_b=str(df1['Unnamed: 2'][0])
b_c=str(df1['Unnamed: 6'][0])
c_a=str(df1['Pnl 1 Data'][0])
fdcFeedBreakerList = [g_int_c,g_ext_c,NULL,NULL,n_int_c,n_ext_c,NULL,NULL,a_int_c,a_ext_c,NULL,NULL,b_int_c,b_ext_c,NULL,NULL,c_int_c,c_ext_c,NULL,NULL,a_b,c_a,b_c,NULL,breakertype,deviceid,breakerid] #3 pole breake riwht monitoring, an nuetral and a group (current & voltage)
breakerid+=1
fdcFeedBreakerString=",".join(map(str,fdcFeedBreakerList))
fdcFeedBreakerString=fdcFeedBreakerString+"\n"
print "fdcFeedBreakerString" + str(fdcFeedBreakerString)
# 2bc. FDC Feed Braeker "List"
brk1_int_c = ''
brk1_ext_c = ''
brk2_int_c = ''
brk2_ext_c = ''
def parseTwoPoleBreakers(breakerStartVal1,breakerStartVal2,inputList,i):
#global brk1_int_c,brk1_ext_c,brk2_int_c,brk2_ext_c
additionValue=(i*6)
#2 Pole breaker with monitring (current only) (a-b)
aStartVal=breakerStartVal1
bStartVal=breakerStartVal2
if i>=1:
aRowNum=aStartVal
bRowNum=bStartVal
else:
aRowNum=aStartVal+additionValue
bRowNum=bStartVal+additionValue
brk1_int_c=str(df1['Unnamed: 1'][aRowNum])#starts at row 7,13,19,25,31,37,43,49. addition of 6
brk1_ext_c=str(df1['Unnamed: 2'][aRowNum])
brk2_int_c=str(df1['Unnamed: 1'][bRowNum])
brk2_ext_c=str(df1['Unnamed: 2'][bRowNum])
two_pbwmco_a_b=inputList
two_pbwmco_a_bString=",".join(map(str,two_pbwmco_a_b))
two_pbwmco_a_bString=two_pbwmco_a_bString+"\n"
print two_pbwmco_a_bString
print "breaker id" + str(breakerid)
two_pbwmco_a_bList2=[NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,brk1_int_c,brk1_ext_c,NULL,NULL,brk2_int_c,brk2_ext_c,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,breakertype,deviceid,breakerid]
two_pbwmco_b_cList2=[NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,brk1_int_c,brk1_ext_c,NULL,NULL,brk2_int_c,brk2_ext_c,NULL,NULL,NULL,NULL,NULL,NULL,breakertype,deviceid,breakerid]
two_pbwmco_c_aList2=[NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,brk2_int_c,brk2_ext_c,NULL,NULL,NULL,NULL,NULL,NULL,brk1_int_c,brk1_ext_c,NULL,NULL,NULL,NULL,NULL,NULL,breakertype,deviceid,breakerid]
i=0
while (i<7):
parseTwoPoleBreakers(7,8,two_pbwmco_a_bList2,i)
breakerid+=1
parseTwoPoleBreakers(9,10,two_pbwmco_b_cList2,i)
breakerid+=1
parseTwoPoleBreakers(11,12,two_pbwmco_c_aList2,i)
breakerid+=1
i+=1
Es ist durchaus möglich, dass ‚globale brk1_int_c, brk1_ext_c, brk2_int_c, brk2_ext_c‘ auch akzeptabel ist, aber ich habe es noch nie getestet und habe Globals noch nie so verwendet –
Ich habe das Pech, dass ich mal globale Variablen benutzt habe. Sie können sie tatsächlich in einer Linie machen. – zondo