【发布时间】:2019-03-18 14:41:09
【问题描述】:
我想知道如何通过 Return 检索循环的所有值。 在我的第一个函数中,我循环恢复我的所有文件夹、子文件夹。然后我回到 pathFiles
在我的第二个函数中,我在文件夹中的所有文件上测试我的 linux 命令,但问题是:我的函数只测试循环的最后一个结果,而不是所有值。
from ftplib import FTP
import ftplib
import os
import errno
import time
class ProcessFile:
path= "FolderFiles"
target=" /var/www/folder/Output"
extract=""
monitoring=""
bash="unrar "
@staticmethod
def returnPath():
pathFiles= []
for root, dirs, files in os.walk(ProcessFile.path, topdown=True):
for name in dirs:
os.path.join(root, name)
for name in files:
pathFiles= os.path.join(root, name)
print(pathFiles)
return pathFiles
@staticmethod
def testArchive(pathFile):
monitoring = ProcessFile.bash+"t "+pathFile
verifyFiles = os.system(monitoring)
return verifyFiles
def testCodeRetour():
myPath = ProcessFile.returnPath()
print(myPath)
你知道它是如何工作的吗?
感谢您的帮助
【问题讨论】:
-
Do you have any idea how it works?- 你写的代码吗? -
您是否打算创建
ProcessFile实例?或者你只是用它来包含那些静态方法?通常在 Python 中,你不会创建一个只有静态方法的类 - 你会将这些方法编写为 standalone 函数和它们自己模块中的变量,然后导入模块。