英文:
Why does 'import mysql.connector' not work but 'from mysql import connector' does?
问题
我开始学习一些SQL Python,刚开始时遇到了这个现象。我可以
from mysql import connector
但不能
import mysql.connector
这是为什么?
我还可以在第一行去掉导入语句,第二行仍然能够正常工作。
英文:
I'm starting to learn some SQL Python and upon starting I stumbled over this phenomenon. I can
from mysql import connector
but not
import mysql.connector
What is the reason for this?
I can also leave away the import statement in the first line for the second line to still work.
答案1
得分: 1
因为 import mysql.connector
意味着 connector
是一个模块,而 from mysql import connector
意味着它是模块内的对象/类/变量。
英文:
That would be because import mysql.connector
implies that connector
is a module, whereas from mysql import connector
implies that it's an object/class/variable inside the module.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论