我手动移植Mingus(2to3不起作用)。其中大部分都很简单,只需完全限定包和模块名称。同样将括号括在raise
个参数中。
但是我遇到了mingus \ midi \ pyfluidsynth.py的第30-37行问题
import time
from ctypes import *
from ctypes.util import find_library
lib = find_library('fluidsynth') or find_library('libfluidsynth')\
or find_library('libfluidsynth-1')
if lib is None:
raise (ImportError, "Couldn't find the FluidSynth library.")
第37行这会引发运行时错误:
TypeError: exceptions must derive from BaseException
如何移植这个?
答案 0 :(得分:0)
try:
from somelib import *
except ImportError:
raise ImportError("Couldn't find the FluidSynth library.")
答案 1 :(得分:0)
这有效
lib = find_library('fluidsynth') or find_library('libfluidsynth')\
or find_library('libfluidsynth-1')
if lib is None:
raise ImportError( "Couldn't find the FluidSynth library.")