Python 从函数返回所有路径值
我想知道如何通过返回来检索循环的所有值。 在我的第一个函数中,我循环恢复我的所有文件夹、子文件夹。然后我回到pathFiles 在第二个函数中,我在文件夹中的所有文件上测试linux命令,但问题是:我的函数只测试循环的最后一个结果,而不是所有值Python 从函数返回所有路径值,python,for-loop,path,Python,For Loop,Path,我想知道如何通过返回来检索循环的所有值。 在我的第一个函数中,我循环恢复我的所有文件夹、子文件夹。然后我回到pathFiles 在第二个函数中,我在文件夹中的所有文件上测试linux命令,但问题是:我的函数只测试循环的最后一个结果,而不是所有值 from ftplib import FTP import ftplib import os import errno import time class ProcessFile: path= "FolderFiles" target=" /v
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)
你知道它是怎么工作的吗
感谢您的帮助列表
pathFiles=[]
从未使用过。也许你想在里面加些什么?如果是这种情况,那么你必须解决一些问题
在循环中:
for name in files:
pathFiles= os.path.join(root, name)
print(pathFiles)
将名称pathFiles
更改为pathFile
,然后将其附加到列表中
for name in files:
pathFile= os.path.join(root, name)
print(pathFile)
pathFiles.append(pathFile)
从不使用列表
pathFiles=[]
。也许你想在里面加些什么?如果是这种情况,那么你必须解决一些问题
在循环中:
for name in files:
pathFiles= os.path.join(root, name)
print(pathFiles)
将名称pathFiles
更改为pathFile
,然后将其附加到列表中
for name in files:
pathFile= os.path.join(root, name)
print(pathFile)
pathFiles.append(pathFile)
您知道它是如何工作的吗?
-您编写了该代码吗?您是否打算创建一个ProcessFile
实例?或者您只是使用它来包含那些静态方法?通常,在Python中,您不会创建一个只包含静态方法的类,而是将这些方法作为独立函数编写,并将变量放在它们自己的模块中,然后导入模块你知道它是如何工作的吗?
-你写了那段代码吗?你有没有想过创建一个ProcessFile
实例?或者您只是使用它来包含那些静态方法?通常,在Python中,你不会创建一个只包含静态方法的类——你会将这些方法作为独立函数编写,并将变量放在它们自己的模块中,然后导入模块|