首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python/PSSE错误: TypeError:需要一个整数

Python/PSSE错误: TypeError:需要一个整数
EN

Stack Overflow用户
提问于 2017-07-12 04:12:04
回答 1查看 494关注 0票数 1

在尝试将信息加载到PSSE中时,我在代码末尾收到一个错误。我的目标是一旦所有的数据都按照我想要的方式进行了组织,下一步就是使用这些组织好的数据并将其导入PSSE。之前的一切都可以工作,但是一旦我使用了PSSE API,就什么都不能工作了。我得到这个错误: psspy.bsys(1,0,0.0,0.0,0,[],1,bus,0,[],0,[])文件".\psspy.py",行46020,in bsys TypeError:需要一个整数。

代码语言:javascript
复制
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])
EN

回答 1

Stack Overflow用户

发布于 2017-07-12 06:05:39

代码语言:javascript
复制
for bus in busses_in_year[location]:
    print(bus)

这打印的是什么?从前面的代码中,我认为bus实际上是一个tuple

代码语言:javascript
复制
busses_in_year[location].append((bus, change, isload))

当您使用[bus]调用bsys时,它将在遍历bus之后使用busses_in_year[location]的最后一个值。函数bsys需要一个整数,但是您给了它完整的tuple

我不确定如何修复您的代码,因为只乘坐一年中的最后一辆公交车可能没有意义,所以您可能需要首先修复它。

但是,如果您想正确地解压tuple (bus, change, isload),您可以执行以下操作:

代码语言:javascript
复制
for bus, change, isload in busses_in_year[location]:
    print(bus)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45043694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档