Python 如何找到哪个函数是从";“从-进口”;模块

Python 如何找到哪个函数是从";“从-进口”;模块,python,import,module,libraries,python-importlib,Python,Import,Module,Libraries,Python Importlib,我对“从导入”功能有疑问。例如,我有3个文件:one.py、two.py、three.py three.py文件的内容: from one import * from two import * variable1 variable2 def func1() def func2() def func3() 比方说,我没有上述两个文件的权限,无法打开它们。我的问题是,如何检查从1.py或2.py文件变成哪个函数和哪个变量?有任何命令或类似命令吗?您可以对import语句应用try,但不能

我对“从导入”功能有疑问。例如,我有3个文件:one.py、two.py、three.py

three.py文件的内容:

from one import *
from two import *


variable1
variable2

def func1()

def func2()

def func3()

比方说,我没有上述两个文件的权限,无法打开它们。我的问题是,如何检查从1.py或2.py文件变成哪个函数和哪个变量?有任何命令或类似命令吗?

您可以对import语句应用try,但不能应用

试试看:
从一个进口*
从两个进口*
除恐怖外:
#导入失败后重写变量
var1=。。。
var2=。。。

您可以对import语句应用try-except

试试看:
从一个进口*
从两个进口*
除恐怖外:
#导入失败后重写变量
var1=。。。
var2=。。。

您可以使用
inspect
模块中的
getfile

Return the name of the (text or binary) file in which an object was defined. This will fail with a TypeError if the object is a built-in module, class, or function.

您可以使用
inspect
模块中的
getfile

Return the name of the (text or binary) file in which an object was defined. This will fail with a TypeError if the object is a built-in module, class, or function.

您可以使用模块的名称空间调用函数\变量

使用try/和cheak,但在导入模块时不会出现错误

   try:
       from one
       one.foo()
       one.variable1

   except ImportError as exception:
       print(exception)

   try:
       from two
       two.foo()
       two.variable1

   except ImportError as exception:
       print(exception)

可以使用模块的名称空间调用函数\变量

使用try/和cheak,但在导入模块时不会出现错误

   try:
       from one
       one.foo()
       one.variable1

   except ImportError as exception:
       print(exception)

   try:
       from two
       two.foo()
       two.variable1

   except ImportError as exception:
       print(exception)
如果您使用导入一个,请选中
dir(one)
。如果您正在从一个导入使用
*
,则只需使用
dir()
?如果您使用
导入一个
,请检查
dir(one)
。如果您正在从一个导入使用
*
,那么只需使用
dir()