Py学习  »  Python

从其他/Program python调用函数

pythoncoder • 6 年前 • 1987 次点击  

`第一个程序:First.py

list=["ab","cd","ef"]
for i in list:
    with open("input.txt", "w") as input_file:
        print(" {}".format(i), file = input_file)

预期产量:

ab
cd
ef

但我得到了输出:

ef

第二个程序:Second.py

input_file = open('input.txt','r')     

for line in input_file:
    if "ef" in line:
       print(line)

预期产量:

英孚

得到输出:

英孚

现在我想直接调用first.py中的文本文件(input.txt)并在second.py中使用它?`如何从其他程序python调用函数?

编辑:应用的代码块

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/51543
文章 [ 2 ]  |  最新文章 6 年前