python代码中的错误幻数

时间:2017-08-02 14:25:04

标签: python-2.7 dynamic simulation psse

尝试导入psspy模块时遇到一些问题。我有一个包含以下行的python代码:

import os,sys
PYTHONPATH = r'C:\Program Files (x86)\PTI\PSSE32\PSSBIN'

MODELFOLDER = r'C:\Program Files (x86)\PTI\PSSE32\MODELDRW'

sys.path.append(PYTHONPATH)
os.environ['PATH'] += ';' + PYTHONPATH

import psspy
import redirect

# Redirect output from PSSE to Python:
redirect.psse2py()

# Last case:
CASE = r"C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\savnw.sav"
psspy.psseinit(12000)
psspy.case(CASE)

# Convert loads (3 step process):
psspy.conl(-1,1,1)
psspy.conl(-1,1,2,[0,0],[100,0,0,100])
psspy.conl(-1,1,3)

# Convert generators:
psspy.cong()

# Solve for dynamics
psspy.ordr()
psspy.fact()
psspy.tysl()

# Save converted case
case_root = os.path.splitext(CASE)[0]
psspy.save(case_root + "_C.sav")

# Add dynamics data
psspy.dyre_new(dyrefile="C:\Program Files 
(x86)\PTI\PSSE32\EXAMPLE\savnw.dyr")

# Add channels by subsystem
#   BUS VOLTAGE
psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,13,0])
#   MACHINE SPEED
psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,7,0])

# Add channels individually
#   BRANCH MVA
psspy.branch_mva_channel([-1,-1,-1,3001,3002],'1')

# Save snapshot
psspy.snap(sfile="C:\Program Files 
(x86)\PTI\PSSE32\EXAMPLE\python_test.snp")

# Initialize
psspy.strt(outfile="C:\Program Files 
(x86)\PTI\PSSE32\EXAMPLE\python_test_1.out")
psspy.run(tpause=0)

# 3-phase fault on bus 201 (default bus fault is a 3phase and there is no 
bus 200)
psspy.dist_bus_fault(ibus=201)

# Run to 3 cycles
time = 3.0/60.0
psspy.run(tpause=time)

# Clear fault (assuming only part of bus faults)
psspy.dist_clear_fault()
psspy.dist_branch_trip(ibus=201, jbus=151, id='1')

# Run to 20 seconds
time = 20
psspy.run(tpause=time)

#-----------------------------

# Run 2nd fault if you want
psspy.case(case_root + "_C.sav")
psspy.rstr(sfile="C:\Program Files 
(x86)\PTI\PSSE32\EXAMPLE\python_test.snp")

# Initialize
psspy.strt(outfile="C:\Program Files 
(x86)\PTI\PSSE32\EXAMPLE\python_test_2.out")
psspy.run(tpause=0)

# 1-phase fault branch 3001 to 3003
psspy.dist_branch_fault(ibus=3001, jbus=3003, id='1',units=1,values=
[352,-2389])

# Run to 4 cycles
time = 4.0/60.0
psspy.run(tpause=time)

# Clear fault
psspy.dist_clear_fault()
psspy.dist_branch_trip(ibus=3001, jbus=3003, id='1')

# Run to 20 seconds
time = 20
psspy.run(tpause=time)
# Halt
psspy.pssehalt_2()

但我收到此错误:“C:\ Program Files(x86)\ PTI \ PSSE32 \ PSSBIN \ psspy.py中的错误幻数” 文档中没有提及模块名称或设置的任何更改的信息。有人知道如何纠正这个问题吗?感谢!!!

2 个答案:

答案 0 :(得分:1)

Bad Magic Numbers与python版本相关联。

  • PSSE32 - > Python 2.5
  • PSSE33 - > Python 2.7

上面的示例使用PSSE32,因此代码应该在Python 2.7中执行

答案 1 :(得分:0)

由于Python2将于2020年1月正式不受支持,因此考虑将代码更新为Py3是一个好主意。 相应地,PSSE的Py3魔数是版本34。 希望这会有所帮助。