Python 在numba@jitclass中定义字符串
正在尝试JIT我的一个类。整数、浮点或数组没有问题。但是在设置字符串属性时遇到了麻烦Python 在numba@jitclass中定义字符串,python,oop,numba,Python,Oop,Numba,正在尝试JIT我的一个类。整数、浮点或数组没有问题。但是在设置字符串属性时遇到了麻烦 from numba import * spec = [ ('symb',char)] ## define symb as a char @jitclass(spec) class trade_jit: def __init__(self, symb): print(symb) ## this works self.symb = symb ## this
from numba import *
spec = [ ('symb',char)] ## define symb as a char
@jitclass(spec)
class trade_jit:
def __init__(self, symb):
print(symb) ## this works
self.symb = symb ## this doesn't
如果我只有打印语句,它就可以工作
当包含self.symb=symb时,它表示:
File "<string>", line 3:
<source missing, REPL/exec in use?>
文件“”,第3行:
期望的输出是在使用@jitclass时能够设置字符串属性。您是如何运行此代码的?一个标准的python交互式shell,或者IDE,或者其他什么?@JohnGordon正在运行jupyter@thomas.mac你能解决它吗?@florestan你需要将它转换成比特,然后使用.encode()返回到字符串