2017-08-02 4 views
0

Ich habe einige Probleme beim Importieren von Psspy-Modul. Ich habe einen Python-Code mit den folgenden Zeilen:Schlechte magische Zahl in Python-Code

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() 

Aber ich bekomme diese Fehlermeldung: "Falsche magische Zahl in C: \ Program Files (x86) \ PTI \ PSSE32 \ PSSBIN \ psspy.py" Es gibt Keine Informationen in der Dokumentation, die eine Änderung des Modulnamens oder des Setups erwähnen. Weiß jemand, wie man das korrigiert? Vielen Dank!!!

+0

ist es möglich, dass Sie ausgeführt werden habe ich versucht, diesen Code zuerst mit einer anderen (Version des) Python-Interpreters zu starten? In diesem Fall kann das Entfernen aller '* .pyc'-Dateien und' __pycache__'-Verzeichnisse hilfreich sein. –

+3

Mögliches Duplikat von [Was ist der Fehler der magischen Zahl?] (Https://stackoverflow.com/questions/514371/whats-the-bad-magic-number-error) – Carcigenicate

+0

Welche Python-Version ist es genau? – IsaacDj

Antwort

0

Bad Magic Numbers sind mit Python-Versionen verknüpft.

  • PSSE32 -> Python 2.5
  • PSSE33 -> Python 2,7

Das obige Beispiel verwendet PSSE32 und daher sollte der Code in Python 2.7

Verwandte Themen