Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi here a newer version of ths script

sid = -1
flag = 4
string1 = 'NUMBER'
string2 = ['NAME', 'ID']

TEMPLATE = "CONTINGENCY %(name)s \nREMOVE UNIT %(id)s FROM BUS %(number)s\nEND\n"
ierr1, numbers = psspy.amachint(sid, flag, string1)  # machines at all buses
ierr2, name_id = psspy.amachchar(sid, flag, string2) # names and ids

#The name of the contingency will have bus' name and the machine's id
nameCont =[[1] * len(name_id[0])]
n = 0
while n < len(name_id[0]):
    nameCont[0][n] = "'" + name_id[0][n] + name_id[1][n] + "'"
    n +=1

# convert from columns to rows [(num, name, id), (num, name, id)]
num_name_id = zip(*(nameCont + numbers + [name_id[1]]))
confile = open("contingencyC.con", "wb")
for nameCont, number, id in num_name_id:
    confile.write(TEMPLATE % dict(name=nameCont, id=id, number=number))
confile.write ('END')
confile.close()