gpt4 book ai didi

jython - OpenRefine 支持 Python3 吗?

转载 作者:行者123 更新时间:2023-12-02 01:49:18 26 4
gpt4 key购买 nike

我有自己的 Python 库,我想在 OpenRefine 中使用它作为 described here

但是,OpenRefine 中的所有 Python 代码似乎都经过 Jython,它支持 only Python 2

有没有办法在 OpenRefine 中运行 Python3 代码?

干杯

最佳答案

简短回答:不。 Openrefine 使用 Jython,它目前基于 python 2.7,没有立即或短期计划迁移到 3.X 版本。

但是。

只要你的机器上安装了 python3,就有一个技巧可以做到这一点。Python2 允许执行命令行脚本/工具并收集结果。

这个简单的 python2 脚本就可以做到这一点:

# This jython2.7 script has to be executed as jython, not GREL
# It allows you to execute a command (CLI) in the terminal and retrieve the result.

# import basic librairies
import time
import commands
import random
# get status and output of the command
status, output = commands.getstatusoutput(value)
# add a random between 2 and 5s pause to avoid ddos on servers... Be kind to APIs!
time.sleep(random.randint(2, 5))
# returns the result of the command
return output.decode("utf-8")

我用它来执行本地 python3 脚本,但也执行 dig、curls 等...

用例:假设我在 A 列中有一堆 Internet 域。我想在这些域上执行 dig SOA 命令。

  • 我根据 A 创建一个列 B:“dig SOA”+值,它将提供我想要执行的确切命令。
  • 我使用上述 jython 脚本基于 B 创建列 C。
  • 然后我解析结果。

这个脚本是纯Python2,不依赖额外的库,应该永远有效。

免责声明:第三方应用执行本地代码应谨慎执行。

关于jython - OpenRefine 支持 Python3 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70515655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com