[英]tkinter how to import multiple functions from a list to another python file
So I have 2 files, scratch.py and scratch_2.py所以我有 2 个文件,scratch.py 和 scratch_2.py
in scratch.py I have defined 3 functions, and added them to a list在 scratch.py 我定义了 3 个函数,并将它们添加到列表中
when i import the list with the functions from scratch.py into scracth_2.py and try to call one of the functions it shows that they havent been defined当我将带有函数的列表从 scratch.py 导入 scracth_2.py 并尝试调用其中一个函数时,它表明它们尚未定义
Is it possible to add some functions to a list and only import that list so it contains all the functions?是否可以将一些功能添加到列表中并仅导入该列表以使其包含所有功能? scratch.py and scratch_2.py
scratch.py 和scratch_2.py
When you import functions
, functions
is a list containing the three functions you defined, but you did't call them: If you want to use their same names, you have to define them before the calls.当你导入
functions
时, functions
是一个包含你定义的三个函数的列表,但你没有调用它们:如果你想使用它们相同的名字,你必须在调用之前定义它们。 For instance, for f1
:例如,对于
f1
:
f1 = functions[0]
Content of scratch2.py: scratch2.py 的内容:
from scratch import functions
f1 = functions[0]
f1()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.