简体   繁体   English

Python / PSSE错误:TypeError:必须为整数

[英]Python/PSSE Error: TypeError: an integer is required

I am receiving an error at the end of my code when trying to load the information into PSSE. 尝试将信息加载到PSSE时,代码末尾出现错误。 My goal is once all the data was organized how I wanted, the next step was to use that organized data and import it to PSSE. 我的目标是一旦按照我的意愿组织了所有数据,下一步就是使用组织的数据并将其导入PSSE。 Everything before that works but once I use a PSSE API, nothing works. 在此之前的一切都可以使用,但是一旦我使用PSSE API,一切都将无效。 I get this error: psspy.bsys(1,0,[0.0,0.0],0,[],1,[bus],0,[],0,[]) File ".\\psspy.py", line 46020, in bsys TypeError: an integer is required. 我收到此错误:psspy.bsys(1,0,[0.0,0.0],0,[],1,[bus],0,[],0,[])文件“。\\ psspy.py”,行46020,在bsys TypeError中:需要一个整数。

import os, sys

PSSE_LOCATION = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN"
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 *
import tkFileDialog
import tkSimpleDialog
import tkMessageBox



 STUDY_CASE = 'C:\Users\RoszkowskiM\Documents\Cases\Final\ceii_Case1_SUM_2017_5050_MMWG16PF_FINAL.sav'

LOAD_GEN_DATAFILE = 'C:\Users\RoszkowskiM\Documents\CSV Files\ASTECOR_TLA.csv'

psspy.psseinit(10000)
psspy.case(STUDY_CASE)



data = list(csv.reader(open(LOAD_GEN_DATAFILE)))
mydict = {}
for row in data:
year,location,bus,change,isload = row[0:5]
# convert the types from string to Python numbers

change= float(change)
bus = int(bus)

 #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 location not in busses_in_year:
     busses_in_year[location] = []

 #Add the bus to the list of busses that stop at this location
 busses_in_year[location].append((bus, change,isload))


 # assume CSV has columns as described in the doc string
 year = raw_input("Select Year of Study: ")

 location = raw_input(" Select the number associated to the TLA Pocket Location:")

 if year in mydict and location in mydict[year]:  
  busses_in_year = mydict[year]
  print("Here are all the busses at that location for that year: ")
  for bus in busses_in_year[location]:
    print(bus)


 else:
    print("Invalid Year or Location")


if isload.isdigit() and int(isload):    
    psspy.bsys(1,0,[0.0,0.0],0,[],1,[bus],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],[change,0.0,0,-.0,0.0,-.0,0])
for bus in busses_in_year[location]:
    print(bus)

What does this print? 这印什么? From the previous code I think bus is actually a tuple : 从前面的代码中,我认为bus实际上是一个tuple

busses_in_year[location].append((bus, change, isload))

When you call bsys with [bus] it is using the last value of bus after looping through busses_in_year[location] . 当你调用bsys[bus]它使用的最后一个值bus通过循环后busses_in_year[location] The function bsys expects an integer, but you're giving it the full tuple . 函数bsys需要一个整数,但是您bsys它完整​​的tuple

I'm not sure how to fix your code as it might not make sense to just take the last bus in the year, so you probably need to fix that first. 我不确定如何解决您的代码,因为仅仅乘坐一年中的最后一辆公共汽车可能没有意义,因此您可能需要首先解决该问题。

But if you want to properly unpack the tuple (bus, change, isload) you can do the following: 但是,如果要正确拆开tuple (bus, change, isload) ,则可以执行以下操作:

for bus, change, isload in busses_in_year[location]:
    print(bus)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM