私信  •  关注

Richard K Yu

Richard K Yu 最近创建的主题
Richard K Yu 最近回复了
4 年前
回复了 Richard K Yu 创建的主题 » Python从另一个脚本中的函数导入变量

所以我有两份文件来证明这一点。test.py,itemLink变量所在的位置,并导入test.py以显示导入。

这里是test.py:

itemLink = 'no values'
print(itemLink)
def generate():
    itemLink = "predefined_text" #+ itemName.get() + "predefined_tex" + itemSize.get()
    #print(itemLink)

    return itemLink

#we mutate the value of itemLink in the main program
itemLink = generate()

这是import_test.py

from test import itemLink
#Now we just have the modified itemLink value without having to import main function to call in the UI program.
print(itemLink)

下面是调用import_test.py的图片: enter image description here

我这次在主函数中调用了generate方法来修改itemLink的值,然后将itemLink传递到下一个文件中。

告诉我这是不是你要找的。

4 年前
回复了 Richard K Yu 创建的主题 » 如何使for循环在python中更容易理解?

试试这个:

for i in range(10):
    print(i+1)

list_of_numbers = range(1,11)

for number in list_of_numbers:
    print(number)