Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在numba@jitclass中定义字符串_Python_Oop_Numba - Fatal编程技术网

Python 在numba@jitclass中定义字符串

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

正在尝试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 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()返回到字符串