簡體   English   中英

Python / PSSE錯誤:TypeError:必須為整數

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

嘗試將信息加載到PSSE時,代碼末尾出現錯誤。 我的目標是一旦按照我的意願組織了所有數據,下一步就是使用組織的數據並將其導入PSSE。 在此之前的一切都可以使用,但是一旦我使用PSSE API,一切都將無效。 我收到此錯誤: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)

這印什么? 從前面的代碼中,我認為bus實際上是一個tuple

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

當你調用bsys[bus]它使用的最后一個值bus通過循環后busses_in_year[location] 函數bsys需要一個整數,但是您bsys它完整​​的tuple

我不確定如何解決您的代碼,因為僅僅乘坐一年中的最后一輛公共汽車可能沒有意義,因此您可能需要首先解決該問題。

但是,如果要正確拆開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