p+中的Python语法错误+;编译和设置
我正在尝试将py++移植到最新版本的python,我遇到了它抱怨的以下代码。我是python新手。如有任何帮助,我们将不胜感激 错误:p+中的Python语法错误+;编译和设置,python,py++,Python,Py++,我正在尝试将py++移植到最新版本的python,我遇到了它抱怨的以下代码。我是python新手。如有任何帮助,我们将不胜感激 错误: File "C:\tp\python\python34\Lib\site-packages\pyplusplus\gui\wizard.py", line 40 , 'include_paths' : `self._parser_configuration.include_paths` ^ SyntaxEr
File "C:\tp\python\python34\Lib\site-packages\pyplusplus\gui\wizard.py", line
40
, 'include_paths' : `self._parser_configuration.include_paths`
^
SyntaxError: invalid syntax
代码如下:
"""generates Py++ code from the user data"""
CODE_TEMPLATE = \
"""
import os
from pyplusplus import module_builder
#Creating an instance of class that will help you to expose your declarations
mb = module_builder.module_builder_t( [r"%(file_path)s"]
, gccxml_path=r"%(gccxml_path)s"
, working_directory=r"%(working_dir)s"
, include_paths=%(include_paths)s
, define_symbols=%(define_symbols)s )
#Well, don't you want to see what is going on?
mb.print_declarations()
#Creating code creator. After this step you should not modify/customize declarations.
mb.build_code_creator( module_name='pyplusplus' )
#Writing code to file.
mb.write_module( './bindings.cpp' )
"""
class wizard_t( object ):
"""code generator that creates Py++ code"""
def __init__( self
, parser_configuration
, source_file ):
object.__init__( self )
self._parser_configuration = parser_configuration
self._source_file = source_file
def create_code( self ):
global CODE_TEMPLATE
return CODE_TEMPLATE % {
'gccxml_path' : self._parser_configuration.gccxml_path
, 'working_dir' : self._parser_configuration.working_directory
, 'include_paths' : `self._parser_configuration.include_paths`
, 'define_symbols' : `self._parser_configuration.define_symbols`
, "file_path" : `self._source_file`
}
您正在使用Python2语法;Python 3不支持围绕值的反勾号:
`self._parser_configuration.include_paths`
您必须在那里使用repr()
函数:
repr(self._parser_configuration.include_paths)
Backticks(记录为a)是一种非常模糊且很少使用的Python 2语法;您的代码可能是用Python 2编写的。您的代码库中可能还有其他特定于Python-2的语法。为什么要在这些路径周围使用Backticks?这些Backticks只在Python 2中有效,最好用
repr()替换(代码)>调用。非常感谢。这不是我的代码。它是Py++ C++的一部分,用PosithPython来创建Python代码生成器。我正在学习Python,因为我正试图安装这个工具。我真的不太了解Python,以至于它已经解决了。显然代码是为Python 2编写的。
是相当模糊的(语法从语言中删除的原因之一)。