私のコードに問題があります。私は出力文を変数に格納したい。私はfor loop
の外に置いて、ループ内ではなくコードの最後に文を出力します。これは可能ですか?これは私が試みたものですが、複数のステートメントを出力する必要がある場合は1つの出力しか得られません。変数を出力して出力を後で保存する
outputs=[]
if Year in mydict and data_location in mydict[Year]:
busses_in_year = mydict[Year]
#print("Here are all the busses at that location for that year and the new LOAD TOTAL: ")
#print("\n")
#Busnum, busname,scaled_power read from excel sheet matching year and location
for busnum,busname,scaled_power in busses_in_year[data_location]:
scaled_power= float(scaled_power)
busnum = int(busnum)
output='Bus #: {}\t Area Station: {}\t New Load Total: {} MW\t'
formatted = output.format(busnum, busname, scaled_power)
outputs.append(formatted)
psspy.bsys(1,0,[0.0,0.0],0,[],1,[busnum],0,[],0,[])
psspy.scal_2(1,0,1,[0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0])
psspy.scal_2(0,1,2,[0,1,0,1,0],[scaled_power,0.0,0,-.0,0.0,-.0,0])
psspy.fdns([0,0,1,1,0,0,0,0])
else:
exit
print(formatted)
なぜ 'outputs'ではなく' formatted'を出力していますか? 'outputs'はすべてのフォーマットされた出力文字列のリストです。 – birryree