无法从php访问python数组

2024-04-26 22:16:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个密码snippets:- 你知道吗

1)获取\u pos \u tags.py

import sys
import json
from nltk.tokenize import word_tokenize
from nltk.tag import pos_tag

def getPOSTags(sentence=sys.argv[1]):
    sentence_s=str(sentence)
    word_token=word_tokenize(sentence_s)
    print word_token
    word_POS_tags=pos_tag(word_token)

if __name__=='__main__':
    getPOSTags()

2)test.php

<?php
$sentence="I became the king of rome";
echo("python get_pos_tags.py "."'".$sentence."'",$output);
var_dump($output);

当我在xampp上运行test.php时,我收到的xampp输出为null,而我应该以python List的形式得到输出。有人能帮我解释一下这段代码有什么问题吗?我用的是MacOSXElCapitan和PHP7


Tags: frompypostestimporttokentagsys