python 如何导入数字开头的包比如from 123abc.234cbd import main就会提示SyntaxError: invalid syntax 这个是为什么?
2 回答

HUWWW
TA贡献1874条经验 获得超12个赞
因为这么写不符合Python的Parser(词法分析器)的规则,不能被正确解析。
以你的要求为例,你可以这么写:
main = __import__('main', fromlist = '123abc.234cbd')

侃侃尔雅
TA贡献1801条经验 获得超16个赞
abc=__import__('123abc.234cbd')
form abc import main
不要以数字开头命名包!!
用google搜索
python package number begin
第一条就是In python, how to import filename sta...
添加回答
举报
0/150
提交
取消