Integer Required for Function

163 views Asked by At

The error in the code is

psspy.three_wnd_winding_data_3(from_,to,last_bus,r"""1""",1,[_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f, max_value, min_value,_f,_f,_f]) 

TypeError: an integer is required 

I thought I already converted the string into an integer. I am confused. Because the other variables year_link, tla_2, min_value, max_value did not require me to use isinstance and isdigit. The variables are being transferred into the psspy function array. The error says, it's reading a string value for last_bus. Does anyone know how to fix this and can explain to me why I have to convert the string for the last column of the excel sheet. Excel Sheet

for row in data:
     year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16]
     if isinstance(last_bus, str) and year_link==year and tla_2==location and last_bus.isdigit() is True:
         min_value=float(min_value)
         max_value=float(max_value)
         last_bus=int(last_bus)

         output = 'From Bus #: {}\tTo Bus #: {}\tLast Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t'
         print(output.format(from_, to,last_bus,name2, min_value, max_value))
         print("\n")
         psspy.three_wnd_winding_data_3(from_,to, last_bus,r"""1""",1,[_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f, max_value, min_value,_f,_f,_f]) 
     else:
         exit
1

There are 1 answers

0
jeschwar On

Excel doesn't have an integer data type; so from_ and to could actually be float objects in python.

Sending arguments to psspy functions in the format the record macro feature gives you is error-prone. The following approach using keyword arguments is better:

psspy.three_wnd_winding_data_3(
    ibus=int(from_),              # H winding bus
    jbus=int(to),                 # X winding bus
    kbus=int(last_bus),           # Y winding bus
    ckt='1',                      # circuit ID
    warg=1,                       # winding number
    realari9=float(max_value),    # VMAi
    realari10=float(min_value),   # VMIi
)    

Reading the docstring is crucial here. You can read the API documentation.