如何清除通过py4j从Java接收到的数组到Python?

时间:2019-04-09 13:54:58

标签: java python py4j

我写了这个简单的代码来从Python运行Java类。应该发送一个长字符串,执行一些预处理并返回一个包含以下内容的Java数组:

  1. 原始字符串(文章[0])
  2. 预处理后的字符串(文章[1])。

除了将当前字符串一直添加到第二个索引“ articles [1]”中的所有先前字符串中而无需清除不是仅打印当前字符串的“ articles [0]”之外,它的工作原理非常理想。我尝试关闭并再次运行,并确保它在Java版本中正常运行。另外,我尝试将其传输到列表“ docs”以保存它,然后在Python中清除该数组,当我打印“ aticles [1]”之后,将其获取为空,但下次运行时,docs [1]仍然具有所有功能先前清理过的字符串。什么都没用!

from py4j.java_gateway import JavaGateway

doc="A NEWS ARTICLES"
gateway = JavaGateway()  


preprocess_app = gateway.entry_point 




articles=preprocess_app.clean_article(doc)
#transfer it to python list 
docs=list(articles)
articles[0]=""
articles[1]=""

#docs has all previous strings while articles[1] is empty
print(docs[1])
print(articles[1])

0 个答案:

没有答案
相关问题