2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 为什么python的命名不能以数字开头 Python模块名称以数字开头

为什么python的命名不能以数字开头 Python模块名称以数字开头

时间:2022-09-17 04:52:17

相关推荐

为什么python的命名不能以数字开头 Python模块名称以数字开头

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

or even

123foo = __import__('123foo')

They are both syntax errors. You can do

foo123 = __import__('123foo')

But it's better to just rename the module to foo123 and import it normally instead.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。