程序功能:
python 打开一个文件,按行读取分拆数据,对数据进行格式转换,存储到list中
#打开文件
with open(optns['PSASP_FILE']+'\LF.L1','r') as fid:
textLines = fid.read().splitlines();#按行取内容
for row in range(0,len(textLines)):#对每一行进行提取内容
ts = textLines[row].split(',');#按‘,’进行分拆
idbus = row+1;#as row starts from 0
Bus_Name = ts[0].replace("'","").strip();#替换‘‘’同时去掉空格
busNamemap[idbus] = Bus_Name;
Vbase = float(ts[1]);#数据类型转换
Area = int(ts[2]);
Vmax = float(ts[3]);
Vmin = float(ts[4]);
CB1 = float(ts[5]);
CB3 = float(ts[6]);
bustype = 1; #initialized 1 and modified by load and generator data.
serv = 0;#flag of whether in service
V0 = 1.0;# initial voltage bus
Ang0 = 0.0;
busMap[idbus] = len(busData);
# 0 1 2 3 4 5 6 7 8 9 10 11 12
busData.append([idbus, Bus_Name, Vbase, Area, Vmax, Vmin, CB1, CB3, Bus_Name, bustype,serv,V0,Ang0]);#数据存储
if optns['OUTPUT_LEVEL'] > 2:
PrintT(optns,'Finish to read Bus info, Start to read AC Line...');