Python列表未打印

2024-05-15 01:47:02 发布

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

我遇到了一个很奇怪的问题。这是我的密码。你知道吗

from nltk.parse.stanford import StanfordParser

stanford_parser_dir = 'stanford-parser/'
eng_model_path = stanford_parser_dir  + "stanford-parser-models/edu/stanford/nlp/models/lexparser/englishRNN.ser.gz"
my_path_to_models_jar = stanford_parser_dir  + "stanford-parser-3.5.2-models.jar"
my_path_to_jar = stanford_parser_dir  + "stanford-parser.jar"
parser=StanfordParser(model_path=eng_model_path, path_to_models_jar=my_path_to_models_jar, path_to_jar=my_path_to_jar)

a = list(parser.raw_parse("the quick brown fox jumps over the lazy dog"))
print a

什么也没印出来。你知道吗

现在,当我使用-I标志运行代码时,比如python -i filename.py并尝试print a,会出现以下错误。你知道吗

>>> a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined

但是现在,当我在同一个shell中再次执行最后两行时,它工作得很好。。!你知道吗

>>> a = list(parser.raw_parse("the quick brown fox jumps over the lazy dog"))
>>> print a
[Tree('ROOT', [Tree('S', [Tree('NP', [Tree('DT', ['the']), Tree('JJ', ['quick']), Tree('NN', ['brown']), Tree('NN', ['fox'])]), Tree('VP', [Tree('VBZ', ['jumps']), Tree('PP', [Tree('IN', ['over']), Tree('NP', [Tree('DT', ['the']), Tree('JJ', ['lazy']), Tree('NN', ['dog'])])])])])])]

那么,当我使用python filename.py运行文件时,为什么不打印为输出呢?你知道吗


Tags: thetopathtreeparsermodelparsemodels

热门问题