Python执行器(Embedded Python)

执行 Python 代码:

  1. <?php
  2.  
  3. function test() {
  4. return 'Test';
  5. }
  6.  
  7. $py = <<<EOT
  8. import phalcon
  9.  
  10. print phalcon.call('test')
  11. print phalcon.call('sha1', ('tuple',))
  12. print phalcon.call('sha1', ['list'])
  13. EOT;
  14.  
  15. Phalcon\Py::exec($py);

导入模块:

  1. <?php
  2.  
  3. $phalcon = Phalcon\Py::import('phalcon');
  4. Phalcon\Py::callFunction($phalcon, 'call', 'test');

调用对象方法:

  1. <?php
  2.  
  3. $list = Phalcon\Py::list([5,1,2,3,4]);
  4. Phalcon\Py::callMethod($list, 'sort');

原文: http://www.myleftstudio.com/reference/py.html