gpt4 book ai didi

Python 不接受导入模块名称为 '-'

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:44:01 24 4
gpt4 key购买 nike

我有一个名为“downloadflat-modular.py”的模块,python 无法导入该模块

Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import downloadflat-modular
File "<stdin>", line 1
import downloadflat-modular
^
SyntaxError: invalid syntax
>>> from downloadflat-modular import *
File "<stdin>", line 1
from downloadflat-modular import *
^
SyntaxError: invalid syntax
>>>

这是限制吗?

uname -a
Linux ubuntu 3.16.0-30-generic #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

最佳答案

包名称是标识符,因此它们不能包含连字符。

python 中的标识符必须以小写/大写字母或下划线开头,名称的其余部分可以包含数字。


根据 PEP8,建议的样式如下:

https://www.python.org/dev/peps/pep-0008/#package-and-module-names

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.

关于Python 不接受导入模块名称为 '-',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40604145/

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