简体   繁体   English

python代码中的错误幻数

[英]Bad magic number in python code

I have some problems while trying to import psspy module.我在尝试导入 psspy 模块时遇到了一些问题。 I have a python code containing the following lines:我有一个包含以下几行的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()

But I get this error: "Bad magic number in C:\\Program Files (x86)\\PTI\\PSSE32\\PSSBIN\\psspy.py" There is no information in the documentation that mentions any change in module name or setup.但我收到此错误:“C:\\Program Files (x86)\\PTI\\PSSE32\\PSSBIN\\psspy.py 中的错误幻数”文档中没有任何信息提及模块名称或设置的任何更改。 Does anybody know how to correct this?有谁知道如何纠正这个问题? Thanks!!!谢谢!!!

Bad Magic Numbers are associated with python versions.错误的幻数与 python 版本相关。

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

The above example uses PSSE32 and hence the code should be executed in Python 2.7上面的例子使用 PSSE32,因此代码应该在 Python 2.7 中执行

Since Python2 will be officially not supported by Jan 2020, it will be a good idea to considering updating the code to Py3.由于 Python2 将在 2020 年 1 月正式不支持,因此考虑将代码更新到 Py3 将是一个好主意。 Correspondingly the Magic Number of Py3 for PSSE is version 34. Hope this helps.相应地,PSSE 的 Py3 幻数是版本 34。希望这会有所帮助。

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

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