我在configparser.py中得到了一个无效的语法错误。

时间:2022-04-02 01:31:48

I'm trying to get the pymysql module working with python3 on a Macintosh. Note that I am a beginning python user who decided to switch from ruby and am trying to build a simple (sigh) database project to drive my learning python.

我试着让pymysql模块在Macintosh上与python3合作。注意,我是一个刚开始使用python的用户,他们决定从ruby中切换,并尝试构建一个简单的(叹号)数据库项目来驱动我的学习python。

In a simple (I thought) test program, I am getting a syntax error in confiparser.py (which is used by the pymysql module)

在一个简单的(我认为)测试程序中,我得到了一个信任语法错误。py(由pymysql模块使用)

def __init__(self, defaults=None, dict_type=_default_dict,
             allow_no_value=False, *, delimiters=('=', ':'),
             comment_prefixes=('#', ';'), inline_comment_prefixes=None,
             strict=True, empty_lines_in_values=True,
             default_section=DEFAULTSECT,
             interpolation=_UNSET):

According to Komodo, the error is on the second line. I assume it is related to the asterix but regardless, I don't know why there would be a problem like this with a standard Python module.

据Komodo报道,错误发生在第二行。我假设它与asterix有关,但无论如何,我不知道为什么会出现这样的问题,使用标准的Python模块。

Anyone seen this before?

有人见过吗?

2 个解决方案

#1


1  

You're most certainly running the code with a 2.x interpreter. I wonder why it even tries to import 3.x libraries, perhaps the answer lies in your installation process - but that's a different question. Anyway, this (before any other imports)

你肯定是用2来运行代码的。x翻译。我想知道为什么它会试图导入3。x库,也许答案就在你的安装过程中——但这是一个不同的问题。无论如何,这(在其他导入之前)

import sys
print(sys.version)

should show which Python version is actually run, as Komodo Edit may be choosing the wrong executable for whatever reason. Alternatively, leave out the parens and it simply fails if run with Python 3.

应该显示哪个Python版本是实际运行的,因为Komodo编辑可能出于某种原因选择了错误的可执行文件。或者,省略parens,如果使用python3运行就会失败。

#2


1  

In Python 3.2 the configparser module does indeed look that way. Importing it works fine from Python 3.2, but not from Python 2.

在Python 3.2中,configparser模块确实看起来是这样的。导入它在Python 3.2中运行良好,但不是来自Python 2。

Am I right in guessing you get the error when you try to run your module with Komodo? Then you just have configured the wrong Python executable.

当你试图用Komodo运行你的模块时,我猜错了吗?然后,您只配置了错误的Python可执行文件。

#1


1  

You're most certainly running the code with a 2.x interpreter. I wonder why it even tries to import 3.x libraries, perhaps the answer lies in your installation process - but that's a different question. Anyway, this (before any other imports)

你肯定是用2来运行代码的。x翻译。我想知道为什么它会试图导入3。x库,也许答案就在你的安装过程中——但这是一个不同的问题。无论如何,这(在其他导入之前)

import sys
print(sys.version)

should show which Python version is actually run, as Komodo Edit may be choosing the wrong executable for whatever reason. Alternatively, leave out the parens and it simply fails if run with Python 3.

应该显示哪个Python版本是实际运行的,因为Komodo编辑可能出于某种原因选择了错误的可执行文件。或者,省略parens,如果使用python3运行就会失败。

#2


1  

In Python 3.2 the configparser module does indeed look that way. Importing it works fine from Python 3.2, but not from Python 2.

在Python 3.2中,configparser模块确实看起来是这样的。导入它在Python 3.2中运行良好,但不是来自Python 2。

Am I right in guessing you get the error when you try to run your module with Komodo? Then you just have configured the wrong Python executable.

当你试图用Komodo运行你的模块时,我猜错了吗?然后,您只配置了错误的Python可执行文件。