isinstance не выводит ничего

Мой код не isinstance ничего при использовании isinstance . Это показано в конце кода. Я попытался tla_2=1 year 1 и tla_2=1 , и никакого выхода не произошло. Является ли мое утверждение isnstance неправильным. Я неправильно зацикливаюсь?

 output = 'From Bus #: {}\tTo Bus #: {}\tTo Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' print(output.format(from_, to,name2, min_value, max_value,last_bus)) 

Лист Excel

 from __future__ import print_function import os.path import win32com.client #--------------------------------------------------------------------------------------------------------------------- xlApp = win32com.client.DispatchEx('Excel.Application') # Running Excel xlsPath = os.path.expanduser('C:\Users\RoszkowskiM\Desktop\UPDATED_LOAD_FORECAST_4.xlsm')# Reading xlsm file wb = xlApp.Workbooks.Open(Filename=xlsPath) # Opening file xlApp.Run('csvfile2')# Running macro---- csvfile2 is the macro name. It is under the "csv" module in the VBA editor wb.Save() xlApp.Quit() #--------------------------------------------------------------------------------------------------------------------- # WHEN RUNNING THE PROGRAM, MAKE SURE THE CSV FILE IS NOT OPEN. # THIS WILL PRODUCE AN ERROR WITH READING AND RUNNING THE MACRO. # THE EXCEL WORKBOOK CAN BE OPEN WHEN RUNNING THE PROGRAM import os, sys #-------------------------------------------------------------------------- #PSSE_LOCATION = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN" #Locating PSSE #sys.path.append(PSSE_LOCATION) #os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION #-------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------- #import psspy #import redirect import csv #psspy.throwPsseExceptions = True from Tkinter import * # File Dialog import tkFileDialog import tkSimpleDialog import tkMessageBox import Tkinter as tk #Pop up window for picking file on PSSE #root = tk.Tk() #root.withdraw() #tkMessageBox.showinfo("Welcome", "Please select case: ") #root.fileName= tkFileDialog.askopenfilename( filetypes = ( ("PSSE CASES", "*.sav"), ("PSSE CASES", "*.raw*") ) ) #STUDY_CASE=root.fileName #psspy.psseinit(10000) # Intialize PSSE #psspy.case(STUDY_CASE) # Upload Case LOAD_GEN_DATAFILE = 'C:\Users\RM\Desktop\Data_2017.csv' # CSV File to Read # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location,empty,year_link,from_,to,digit,min_value,max_value,last_bus #------------------------------------------------------------------------------- # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location data = list(csv.reader(open(LOAD_GEN_DATAFILE))) mydict = {} for row in data: Year,busnum,busname,scaled_power,tla,data_location,empty,year_link,from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[0:16] #If this is a year not seen before, add it to the dictionary if Year not in mydict: mydict[Year] = {} busses_in_year = mydict[Year] if data_location not in busses_in_year: busses_in_year[data_location] = [] #Add the bus to the list of busses that stop at this location busses_in_year[data_location].append((busnum,busname,scaled_power)) #------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------------------------------------------------- #User Input Statement year = raw_input("Please Select Year of Study: ") print("\n") location=raw_input(" \n The list above show the TLA Pockets as well as the ID numbers assigned to them ()\n\n Please enter the ID #: ") #psspy.prompt_output(islct = 6) print("\n") Year=year data_location=location #--------------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- 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' print(output.format(busnum,busname,scaled_power)) #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]) else: exit #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- #------------------------------------------------VOLTAGE ENVLOPES--------------------------------------------------------------------------------------------------------------------------------- for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] output = 'From Bus #: {}\tTo Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' if year_link == year and tla_2==location: from_=int(from_) to=int(to) min_value=float(min_value) max_value=float(max_value) digit=int(digit) print(output.format(from_, to,name2, min_value, max_value)) #_c=psspy.getdefaultchar() #_i=psspy.getdefaultint() #_f=psspy.getdefaultreal() #psspy.two_winding_chng_4(from_,to,'%d'% digit,[_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f, max_value, min_value,_f,_f,_f],[]) else: exit for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] if year_link==year and tla_2==location and isinstance(last_bus, int): output = 'From Bus #: {}\tTo Bus #: {}\tLast Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' print(output.format(from_, to,name2, min_value, max_value,last_bus)) min_value=float(min_value) max_value=float(max_value) #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 #------------------------------------------------VOLTAGE ENVLOPES---------------------------------------------------------------------------------------------------------------------------------- os.remove(LOAD_GEN_DATAFILE) . from __future__ import print_function import os.path import win32com.client #--------------------------------------------------------------------------------------------------------------------- xlApp = win32com.client.DispatchEx('Excel.Application') # Running Excel xlsPath = os.path.expanduser('C:\Users\RoszkowskiM\Desktop\UPDATED_LOAD_FORECAST_4.xlsm')# Reading xlsm file wb = xlApp.Workbooks.Open(Filename=xlsPath) # Opening file xlApp.Run('csvfile2')# Running macro---- csvfile2 is the macro name. It is under the "csv" module in the VBA editor wb.Save() xlApp.Quit() #--------------------------------------------------------------------------------------------------------------------- # WHEN RUNNING THE PROGRAM, MAKE SURE THE CSV FILE IS NOT OPEN. # THIS WILL PRODUCE AN ERROR WITH READING AND RUNNING THE MACRO. # THE EXCEL WORKBOOK CAN BE OPEN WHEN RUNNING THE PROGRAM import os, sys #-------------------------------------------------------------------------- #PSSE_LOCATION = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN" #Locating PSSE #sys.path.append(PSSE_LOCATION) #os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION #-------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------- #import psspy #import redirect import csv #psspy.throwPsseExceptions = True from Tkinter import * # File Dialog import tkFileDialog import tkSimpleDialog import tkMessageBox import Tkinter as tk #Pop up window for picking file on PSSE #root = tk.Tk() #root.withdraw() #tkMessageBox.showinfo("Welcome", "Please select case: ") #root.fileName= tkFileDialog.askopenfilename( filetypes = ( ("PSSE CASES", "*.sav"), ("PSSE CASES", "*.raw*") ) ) #STUDY_CASE=root.fileName #psspy.psseinit(10000) # Intialize PSSE #psspy.case(STUDY_CASE) # Upload Case LOAD_GEN_DATAFILE = 'C:\Users\RM\Desktop\Data_2017.csv' # CSV File to Read # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location,empty,year_link,from_,to,digit,min_value,max_value,last_bus #------------------------------------------------------------------------------- # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location data = list(csv.reader(open(LOAD_GEN_DATAFILE))) mydict = {} for row in data: Year,busnum,busname,scaled_power,tla,data_location,empty,year_link,from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[0:16] #If this is a year not seen before, add it to the dictionary if Year not in mydict: mydict[Year] = {} busses_in_year = mydict[Year] if data_location not in busses_in_year: busses_in_year[data_location] = [] #Add the bus to the list of busses that stop at this location busses_in_year[data_location].append((busnum,busname,scaled_power)) #------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------------------------------------------------- #User Input Statement year = raw_input("Please Select Year of Study: ") print("\n") location=raw_input(" \n The list above show the TLA Pockets as well as the ID numbers assigned to them ()\n\n Please enter the ID #: ") #psspy.prompt_output(islct = 6) print("\n") Year=year data_location=location #--------------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- 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' print(output.format(busnum,busname,scaled_power)) #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]) else: exit #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- #------------------------------------------------VOLTAGE ENVLOPES--------------------------------------------------------------------------------------------------------------------------------- for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] output = 'From Bus #: {}\tTo Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' if year_link == year and tla_2==location: from_=int(from_) to=int(to) min_value=float(min_value) max_value=float(max_value) digit=int(digit) print(output.format(from_, to,name2, min_value, max_value)) #_c=psspy.getdefaultchar() #_i=psspy.getdefaultint() #_f=psspy.getdefaultreal() #psspy.two_winding_chng_4(from_,to,'%d'% digit,[_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f, max_value, min_value,_f,_f,_f],[]) else: exit for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] if year_link==year and tla_2==location and isinstance(last_bus, int): output = 'From Bus #: {}\tTo Bus #: {}\tLast Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' print(output.format(from_, to,name2, min_value, max_value,last_bus)) min_value=float(min_value) max_value=float(max_value) #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 #------------------------------------------------VOLTAGE ENVLOPES---------------------------------------------------------------------------------------------------------------------------------- os.remove(LOAD_GEN_DATAFILE) в from __future__ import print_function import os.path import win32com.client #--------------------------------------------------------------------------------------------------------------------- xlApp = win32com.client.DispatchEx('Excel.Application') # Running Excel xlsPath = os.path.expanduser('C:\Users\RoszkowskiM\Desktop\UPDATED_LOAD_FORECAST_4.xlsm')# Reading xlsm file wb = xlApp.Workbooks.Open(Filename=xlsPath) # Opening file xlApp.Run('csvfile2')# Running macro---- csvfile2 is the macro name. It is under the "csv" module in the VBA editor wb.Save() xlApp.Quit() #--------------------------------------------------------------------------------------------------------------------- # WHEN RUNNING THE PROGRAM, MAKE SURE THE CSV FILE IS NOT OPEN. # THIS WILL PRODUCE AN ERROR WITH READING AND RUNNING THE MACRO. # THE EXCEL WORKBOOK CAN BE OPEN WHEN RUNNING THE PROGRAM import os, sys #-------------------------------------------------------------------------- #PSSE_LOCATION = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN" #Locating PSSE #sys.path.append(PSSE_LOCATION) #os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION #-------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------- #import psspy #import redirect import csv #psspy.throwPsseExceptions = True from Tkinter import * # File Dialog import tkFileDialog import tkSimpleDialog import tkMessageBox import Tkinter as tk #Pop up window for picking file on PSSE #root = tk.Tk() #root.withdraw() #tkMessageBox.showinfo("Welcome", "Please select case: ") #root.fileName= tkFileDialog.askopenfilename( filetypes = ( ("PSSE CASES", "*.sav"), ("PSSE CASES", "*.raw*") ) ) #STUDY_CASE=root.fileName #psspy.psseinit(10000) # Intialize PSSE #psspy.case(STUDY_CASE) # Upload Case LOAD_GEN_DATAFILE = 'C:\Users\RM\Desktop\Data_2017.csv' # CSV File to Read # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location,empty,year_link,from_,to,digit,min_value,max_value,last_bus #------------------------------------------------------------------------------- # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location data = list(csv.reader(open(LOAD_GEN_DATAFILE))) mydict = {} for row in data: Year,busnum,busname,scaled_power,tla,data_location,empty,year_link,from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[0:16] #If this is a year not seen before, add it to the dictionary if Year not in mydict: mydict[Year] = {} busses_in_year = mydict[Year] if data_location not in busses_in_year: busses_in_year[data_location] = [] #Add the bus to the list of busses that stop at this location busses_in_year[data_location].append((busnum,busname,scaled_power)) #------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------------------------------------------------- #User Input Statement year = raw_input("Please Select Year of Study: ") print("\n") location=raw_input(" \n The list above show the TLA Pockets as well as the ID numbers assigned to them ()\n\n Please enter the ID #: ") #psspy.prompt_output(islct = 6) print("\n") Year=year data_location=location #--------------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- 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' print(output.format(busnum,busname,scaled_power)) #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]) else: exit #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- #------------------------------------------------VOLTAGE ENVLOPES--------------------------------------------------------------------------------------------------------------------------------- for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] output = 'From Bus #: {}\tTo Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' if year_link == year and tla_2==location: from_=int(from_) to=int(to) min_value=float(min_value) max_value=float(max_value) digit=int(digit) print(output.format(from_, to,name2, min_value, max_value)) #_c=psspy.getdefaultchar() #_i=psspy.getdefaultint() #_f=psspy.getdefaultreal() #psspy.two_winding_chng_4(from_,to,'%d'% digit,[_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f, max_value, min_value,_f,_f,_f],[]) else: exit for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] if year_link==year and tla_2==location and isinstance(last_bus, int): output = 'From Bus #: {}\tTo Bus #: {}\tLast Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' print(output.format(from_, to,name2, min_value, max_value,last_bus)) min_value=float(min_value) max_value=float(max_value) #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 #------------------------------------------------VOLTAGE ENVLOPES---------------------------------------------------------------------------------------------------------------------------------- os.remove(LOAD_GEN_DATAFILE) в from __future__ import print_function import os.path import win32com.client #--------------------------------------------------------------------------------------------------------------------- xlApp = win32com.client.DispatchEx('Excel.Application') # Running Excel xlsPath = os.path.expanduser('C:\Users\RoszkowskiM\Desktop\UPDATED_LOAD_FORECAST_4.xlsm')# Reading xlsm file wb = xlApp.Workbooks.Open(Filename=xlsPath) # Opening file xlApp.Run('csvfile2')# Running macro---- csvfile2 is the macro name. It is under the "csv" module in the VBA editor wb.Save() xlApp.Quit() #--------------------------------------------------------------------------------------------------------------------- # WHEN RUNNING THE PROGRAM, MAKE SURE THE CSV FILE IS NOT OPEN. # THIS WILL PRODUCE AN ERROR WITH READING AND RUNNING THE MACRO. # THE EXCEL WORKBOOK CAN BE OPEN WHEN RUNNING THE PROGRAM import os, sys #-------------------------------------------------------------------------- #PSSE_LOCATION = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN" #Locating PSSE #sys.path.append(PSSE_LOCATION) #os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION #-------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------- #import psspy #import redirect import csv #psspy.throwPsseExceptions = True from Tkinter import * # File Dialog import tkFileDialog import tkSimpleDialog import tkMessageBox import Tkinter as tk #Pop up window for picking file on PSSE #root = tk.Tk() #root.withdraw() #tkMessageBox.showinfo("Welcome", "Please select case: ") #root.fileName= tkFileDialog.askopenfilename( filetypes = ( ("PSSE CASES", "*.sav"), ("PSSE CASES", "*.raw*") ) ) #STUDY_CASE=root.fileName #psspy.psseinit(10000) # Intialize PSSE #psspy.case(STUDY_CASE) # Upload Case LOAD_GEN_DATAFILE = 'C:\Users\RM\Desktop\Data_2017.csv' # CSV File to Read # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location,empty,year_link,from_,to,digit,min_value,max_value,last_bus #------------------------------------------------------------------------------- # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location data = list(csv.reader(open(LOAD_GEN_DATAFILE))) mydict = {} for row in data: Year,busnum,busname,scaled_power,tla,data_location,empty,year_link,from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[0:16] #If this is a year not seen before, add it to the dictionary if Year not in mydict: mydict[Year] = {} busses_in_year = mydict[Year] if data_location not in busses_in_year: busses_in_year[data_location] = [] #Add the bus to the list of busses that stop at this location busses_in_year[data_location].append((busnum,busname,scaled_power)) #------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------------------------------------------------- #User Input Statement year = raw_input("Please Select Year of Study: ") print("\n") location=raw_input(" \n The list above show the TLA Pockets as well as the ID numbers assigned to them ()\n\n Please enter the ID #: ") #psspy.prompt_output(islct = 6) print("\n") Year=year data_location=location #--------------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- 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' print(output.format(busnum,busname,scaled_power)) #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]) else: exit #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- #------------------------------------------------VOLTAGE ENVLOPES--------------------------------------------------------------------------------------------------------------------------------- for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] output = 'From Bus #: {}\tTo Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' if year_link == year and tla_2==location: from_=int(from_) to=int(to) min_value=float(min_value) max_value=float(max_value) digit=int(digit) print(output.format(from_, to,name2, min_value, max_value)) #_c=psspy.getdefaultchar() #_i=psspy.getdefaultint() #_f=psspy.getdefaultreal() #psspy.two_winding_chng_4(from_,to,'%d'% digit,[_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f, max_value, min_value,_f,_f,_f],[]) else: exit for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] if year_link==year and tla_2==location and isinstance(last_bus, int): output = 'From Bus #: {}\tTo Bus #: {}\tLast Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' print(output.format(from_, to,name2, min_value, max_value,last_bus)) min_value=float(min_value) max_value=float(max_value) #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 #------------------------------------------------VOLTAGE ENVLOPES---------------------------------------------------------------------------------------------------------------------------------- os.remove(LOAD_GEN_DATAFILE) - from __future__ import print_function import os.path import win32com.client #--------------------------------------------------------------------------------------------------------------------- xlApp = win32com.client.DispatchEx('Excel.Application') # Running Excel xlsPath = os.path.expanduser('C:\Users\RoszkowskiM\Desktop\UPDATED_LOAD_FORECAST_4.xlsm')# Reading xlsm file wb = xlApp.Workbooks.Open(Filename=xlsPath) # Opening file xlApp.Run('csvfile2')# Running macro---- csvfile2 is the macro name. It is under the "csv" module in the VBA editor wb.Save() xlApp.Quit() #--------------------------------------------------------------------------------------------------------------------- # WHEN RUNNING THE PROGRAM, MAKE SURE THE CSV FILE IS NOT OPEN. # THIS WILL PRODUCE AN ERROR WITH READING AND RUNNING THE MACRO. # THE EXCEL WORKBOOK CAN BE OPEN WHEN RUNNING THE PROGRAM import os, sys #-------------------------------------------------------------------------- #PSSE_LOCATION = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN" #Locating PSSE #sys.path.append(PSSE_LOCATION) #os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION #-------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------- #import psspy #import redirect import csv #psspy.throwPsseExceptions = True from Tkinter import * # File Dialog import tkFileDialog import tkSimpleDialog import tkMessageBox import Tkinter as tk #Pop up window for picking file on PSSE #root = tk.Tk() #root.withdraw() #tkMessageBox.showinfo("Welcome", "Please select case: ") #root.fileName= tkFileDialog.askopenfilename( filetypes = ( ("PSSE CASES", "*.sav"), ("PSSE CASES", "*.raw*") ) ) #STUDY_CASE=root.fileName #psspy.psseinit(10000) # Intialize PSSE #psspy.case(STUDY_CASE) # Upload Case LOAD_GEN_DATAFILE = 'C:\Users\RM\Desktop\Data_2017.csv' # CSV File to Read # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location,empty,year_link,from_,to,digit,min_value,max_value,last_bus #------------------------------------------------------------------------------- # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location data = list(csv.reader(open(LOAD_GEN_DATAFILE))) mydict = {} for row in data: Year,busnum,busname,scaled_power,tla,data_location,empty,year_link,from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[0:16] #If this is a year not seen before, add it to the dictionary if Year not in mydict: mydict[Year] = {} busses_in_year = mydict[Year] if data_location not in busses_in_year: busses_in_year[data_location] = [] #Add the bus to the list of busses that stop at this location busses_in_year[data_location].append((busnum,busname,scaled_power)) #------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------------------------------------------------- #User Input Statement year = raw_input("Please Select Year of Study: ") print("\n") location=raw_input(" \n The list above show the TLA Pockets as well as the ID numbers assigned to them ()\n\n Please enter the ID #: ") #psspy.prompt_output(islct = 6) print("\n") Year=year data_location=location #--------------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- 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' print(output.format(busnum,busname,scaled_power)) #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]) else: exit #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- #------------------------------------------------VOLTAGE ENVLOPES--------------------------------------------------------------------------------------------------------------------------------- for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] output = 'From Bus #: {}\tTo Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' if year_link == year and tla_2==location: from_=int(from_) to=int(to) min_value=float(min_value) max_value=float(max_value) digit=int(digit) print(output.format(from_, to,name2, min_value, max_value)) #_c=psspy.getdefaultchar() #_i=psspy.getdefaultint() #_f=psspy.getdefaultreal() #psspy.two_winding_chng_4(from_,to,'%d'% digit,[_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f, max_value, min_value,_f,_f,_f],[]) else: exit for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] if year_link==year and tla_2==location and isinstance(last_bus, int): output = 'From Bus #: {}\tTo Bus #: {}\tLast Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' print(output.format(from_, to,name2, min_value, max_value,last_bus)) min_value=float(min_value) max_value=float(max_value) #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 #------------------------------------------------VOLTAGE ENVLOPES---------------------------------------------------------------------------------------------------------------------------------- os.remove(LOAD_GEN_DATAFILE) в from __future__ import print_function import os.path import win32com.client #--------------------------------------------------------------------------------------------------------------------- xlApp = win32com.client.DispatchEx('Excel.Application') # Running Excel xlsPath = os.path.expanduser('C:\Users\RoszkowskiM\Desktop\UPDATED_LOAD_FORECAST_4.xlsm')# Reading xlsm file wb = xlApp.Workbooks.Open(Filename=xlsPath) # Opening file xlApp.Run('csvfile2')# Running macro---- csvfile2 is the macro name. It is under the "csv" module in the VBA editor wb.Save() xlApp.Quit() #--------------------------------------------------------------------------------------------------------------------- # WHEN RUNNING THE PROGRAM, MAKE SURE THE CSV FILE IS NOT OPEN. # THIS WILL PRODUCE AN ERROR WITH READING AND RUNNING THE MACRO. # THE EXCEL WORKBOOK CAN BE OPEN WHEN RUNNING THE PROGRAM import os, sys #-------------------------------------------------------------------------- #PSSE_LOCATION = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN" #Locating PSSE #sys.path.append(PSSE_LOCATION) #os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION #-------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------- #import psspy #import redirect import csv #psspy.throwPsseExceptions = True from Tkinter import * # File Dialog import tkFileDialog import tkSimpleDialog import tkMessageBox import Tkinter as tk #Pop up window for picking file on PSSE #root = tk.Tk() #root.withdraw() #tkMessageBox.showinfo("Welcome", "Please select case: ") #root.fileName= tkFileDialog.askopenfilename( filetypes = ( ("PSSE CASES", "*.sav"), ("PSSE CASES", "*.raw*") ) ) #STUDY_CASE=root.fileName #psspy.psseinit(10000) # Intialize PSSE #psspy.case(STUDY_CASE) # Upload Case LOAD_GEN_DATAFILE = 'C:\Users\RM\Desktop\Data_2017.csv' # CSV File to Read # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location,empty,year_link,from_,to,digit,min_value,max_value,last_bus #------------------------------------------------------------------------------- # read the entire CSV into Python. # CSV has columns starting with Year,busnum,busname,scaled_power,tla,location data = list(csv.reader(open(LOAD_GEN_DATAFILE))) mydict = {} for row in data: Year,busnum,busname,scaled_power,tla,data_location,empty,year_link,from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[0:16] #If this is a year not seen before, add it to the dictionary if Year not in mydict: mydict[Year] = {} busses_in_year = mydict[Year] if data_location not in busses_in_year: busses_in_year[data_location] = [] #Add the bus to the list of busses that stop at this location busses_in_year[data_location].append((busnum,busname,scaled_power)) #------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------------------------------------------------- #User Input Statement year = raw_input("Please Select Year of Study: ") print("\n") location=raw_input(" \n The list above show the TLA Pockets as well as the ID numbers assigned to them ()\n\n Please enter the ID #: ") #psspy.prompt_output(islct = 6) print("\n") Year=year data_location=location #--------------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- 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' print(output.format(busnum,busname,scaled_power)) #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]) else: exit #-------------------------------------------------LOAD FORECASTS-------------------------------------------------------------------- #------------------------------------------------VOLTAGE ENVLOPES--------------------------------------------------------------------------------------------------------------------------------- for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] output = 'From Bus #: {}\tTo Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' if year_link == year and tla_2==location: from_=int(from_) to=int(to) min_value=float(min_value) max_value=float(max_value) digit=int(digit) print(output.format(from_, to,name2, min_value, max_value)) #_c=psspy.getdefaultchar() #_i=psspy.getdefaultint() #_f=psspy.getdefaultreal() #psspy.two_winding_chng_4(from_,to,'%d'% digit,[_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f, max_value, min_value,_f,_f,_f],[]) else: exit for row in data: year_link, from_,to,digit,name2,tla_2,min_value,max_value,last_bus = row[7:16] if year_link==year and tla_2==location and isinstance(last_bus, int): output = 'From Bus #: {}\tTo Bus #: {}\tLast Bus #: {}\t Area Station: {}\t VMIN: {} pu\tVMAX: {} pu\t' print(output.format(from_, to,name2, min_value, max_value,last_bus)) min_value=float(min_value) max_value=float(max_value) #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 #------------------------------------------------VOLTAGE ENVLOPES---------------------------------------------------------------------------------------------------------------------------------- os.remove(LOAD_GEN_DATAFILE) 

2 Solutions collect form web for “isinstance не выводит ничего”

csv.writer способен записывать любые данные (целые числа, поплавки, строки …) в csv . Но csv.reader не выполняет обратную операцию.

last_bus – это данные, непосредственно поступающие из итератора csv.reader . Так что это должна быть строка.

Таким образом, ваш метод isinstance не может вернуть True .

Существует несколько способов проверить, является ли строка целым числом. Я не буду объяснять их здесь, это будет избыточно с множеством уже ответивших на вопросы, но проверьте этот вопрос (который имеет ссылки на другие вопросы и ответы), чтобы реализовать один из ваших вариантов: как я могу проверить, имеет ли строка числовое значение в нем в Python?

Как только вы определили, что строка содержит целое число, просто сделайте int(last_bus) для преобразования в integer.

Хорошо, поэтому я сделал то, что вы сказали. Он выводится правильно, но не psspy функцию psspy .

 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=int(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 в 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=int(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 
  • Каков наилучший способ удаления акцентов в строке юникода Python?
  • Python 3: Asterisk в функции печати
  • Преобразование из utf-16 в utf-8 в Python 3
  • Отрицательное целочисленное деление
  • Использовать Python для записи вывода CSV в STDOUT
  • Python ctypes from_buffer сопоставление с менеджером контекста в файл с отображением памяти (mmap)
  • Anaconda3 2.4 с ошибкой установки python 3.5 (запись процедуры не найдена, Windows 10)
  • Изменение userPassword в OpenLDAP с использованием библиотеки ldap3
  • Python 3.4 многопроцессорная очередь быстрее, чем Pipe, неожиданно
  • Понимание time.perf_counter () и time.process_time ()
  • Как сделать Python3 Python по умолчанию в Geany
  • Python - лучший язык программирования в мире.