【发布时间】:2021-05-04 15:53:14
【问题描述】:
有没有机会使用下面给出的sn-ps?当我运行此代码时,它返回“未安装模块熊猫”
a = "pandas"
try:
import a
print("module ",a," is installed")
except ModuleNotFoundError:
print("module ",a," is not installed")
但是当我运行下面给出的代码时:
try:
import pandas
print("module pandas is installed")
except ModuleNotFoundError:
print("module pandas is not installed")
它返回“模块 pandas 已安装”。
它们有什么区别?
【问题讨论】:
-
你可能想要
eval("import %s" % a)在第一个sn-p 中。 -
不试就试一下,你就会明白其中的区别。 a = "熊猫" 导入 a 。错误将是“ModuleNotFoundError: No module named 'a'”
-
你的标题和你的身体不是同一个问题。请修复。
标签: python try-except