Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在一个方法中使用数组,该方法具有文件目录的参数,并在另一个python文件中返回数组?_Python_File_Directory - Fatal编程技术网

如何在一个方法中使用数组,该方法具有文件目录的参数,并在另一个python文件中返回数组?

如何在一个方法中使用数组,该方法具有文件目录的参数,并在另一个python文件中返回数组?,python,file,directory,Python,File,Directory,下面是将源目录作为方法参数并返回数组的方法。 此方法所做的是转到word文档的源目录,提取所有word文档的信息,然后将它们存储在一个数组中。然后返回该数组的方法由word文档列表组成 问题是如何使用返回的数组并在另一个python文件中调用该方法?请帮忙,谢谢!!:(( 你可以这样做 file1.py: def get_ednotes(str2): directory = str2 my_text = docx2txt.process(directory) ... f

下面是将源目录作为方法参数并返回数组的方法。 此方法所做的是转到word文档的源目录,提取所有word文档的信息,然后将它们存储在一个数组中。然后返回该数组的方法由word文档列表组成

问题是如何使用返回的数组并在另一个python文件中调用该方法?请帮忙,谢谢!!:((

你可以这样做

file1.py:

def get_ednotes(str2):
    directory = str2
    my_text = docx2txt.process(directory)
    ...
file2.py:

from file1 import get_ednotes

root_dir = "../dataprep/source_documents"

for filename in os.listdir(root_dir):
    str2 = root_dir + '/' + filename
    arr = get_ednotes(str2)
    print arr
from file1 import get_ednotes

root_dir = "../dataprep/source_documents"

for filename in os.listdir(root_dir):
    str2 = root_dir + '/' + filename
    arr = get_ednotes(str2)
    print arr