如何通过apache thrift生成python 3兼容代码

时间:2017-06-15 05:05:08

标签: python thrift

此命令生成python2代码:

thrift -r -gen py temp.thrift

然后我尝试了:

thrift -r -gen py3 temp.thrift

但这不起作用。

1 个答案:

答案 0 :(得分:1)

命令行帮助显示所有选项:

thrift  --help

这些都是今天在master中提供的与python相关的选项:

  py (Python):
    twisted:         Generate Twisted-friendly RPC services.
    tornado:         Generate code for use with Tornado.
    no_utf8strings:  Do not Encode/decode strings using utf8 in the generated code. Basically no effect for Python 3.
    coding=CODING:   Add file encoding declare in generated file.
    slots:           Generate code using slots for instance members.
    dynamic:         Generate dynamic code, less code generated but slower.
    dynbase=CLS      Derive generated classes from class CLS instead of TBase.
    dynfrozen=CLS    Derive generated immutable classes from class CLS instead of TFrozenBase.
    dynexc=CLS       Derive generated exceptions from CLS instead of TExceptionBase.
    dynimport='from foo.bar import CLS'
                     Add an import line to generated code to find the dynbase class.
    package_prefix='top.package.'
                     Package prefix for generated files.
    old_style:       Deprecated. Generate old-style classes.

根据THRIFT-1857,py 3应该从0.9开始可用。