本文介绍了Python模块名称以数字开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试在python(.py文件)中导入模块时,它给出了语法错误.模块名称以数字开头.这是语法错误的原因吗?
When I try to import a module in python(.py file) it gives a syntax error. The module name starts with a numeral. Is that the reason for the syntax error?
推荐答案是的,这就是语法错误的原因.无论如何,都有多种导入方法,但是最好重命名模块.
Yes, that is the reason for the syntax error. There are various ways of importing it anyway, but it's better to rename the module.
原因是变量名不能以数字开头.因此,你不能做
The reason is that variable names can't start with a numeral. Hence you can't do
import 123foo甚至
123foo = __import__('123foo')它们都是语法错误.你可以做
They are both syntax errors. You can do
foo123 = __import__('123foo')但是最好将模块重命名为foo123,然后正常地导入它.
But it's better to just rename the module to foo123 and import it normally instead.
更多推荐
Python模块名称以数字开头
发布评论