数据复制Cython

时间:2019-01-06 12:33:05

标签: python c cython

我有一个.pyx文件,其中大文件正在逐块扫描。 Ex- 100 MB数据被扫描成10个部分,每个部分10 MB

在执行此操作时,我具有以下两个值     -文件的偏移量     -以及要扫描的数据长度

我想将数据的每个部分复制到一个随机的Python空列表中。

我这样做的方式是:

class abc
..
cdef object buff

def do_scan(self,...)
   ...
   self.buff = []
   ...
   buff.append(PyString_FromStringAndSize(<char *>offset,length))
   ...

   fh = open ("tmpf.bin","wb")
   cPickle.dump(buff,fh)
   fh.close()
   ...

...
Error:
NameError: PyString_FromStringAndSize is not defined

这没有给我想要的输出。

任何人都可以帮助我如何将数据复制到Python对象中?

1 个答案:

答案 0 :(得分:0)

根据错误消息,您的迫在眉睫的问题更加明确:您尚未告知Cython有关public class MainActivity extends AppCompatActivity { private RecyclerView recyclerView; private int[] images = {R.drawable.img_2321, R.drawable.img_2322, R.drawable.img_2323, R.drawable.img_2325, R.drawable.img_2326, R.drawable.img_2328, R.drawable.img_2329, R.drawable.img_2333, R.drawable.img_2335, R.drawable.img_2356, R.drawable.img_2358, R.drawable.img_2359, R.drawable.img_2360, R.drawable.img_2361, R.drawable.img_2363, R.drawable.img_2365, R.drawable.img_2366, R.drawable.img_2383, R.drawable.img_2390, R.drawable.img_2393, R.drawable.img_2394, R.drawable.img_2396, R.drawable.img_2397, R.drawable.img_2398, R.drawable.img_2454, R.drawable.img_2455, R.drawable.img_2456, R.drawable.img_2457, R.drawable.img_2458, R.drawable.img_2465}; private RecyclerView.LayoutManager layoutManager; private RecyclerView.Adapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = findViewById(R.id.recyclerView); recyclerView.setHasFixedSize(true); layoutManager = new GridLayoutManager(this, 2); recyclerView.setLayoutManager(layoutManager); adapter = new RecyclerAdapter(images); recyclerView.setAdapter(adapter); } } 的信息。最简单的方法是从Cython提供的默认CPython包装器中PyString_FromStringAndSize进行

cimport