Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Return all Path value from function
I would like to know how to retrieve all the values of my loop via a Return. In my first function, I loop to recover all my folders, subfolders. Then I go back to pathFiles

In my second function, I test my linux command on all files in folders, but the problem is this: my function only tests the last result of my loop and not all values.

from ftplib import FTP
import ftplib
import os
import errno
import time

class ProcessFile:
  path= "FolderFiles"
  target=" /var/www/folder/Output"
  bash="unrar "

  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)
    return pathFiles 

  def testArchive(pathFile):
    monitoring = ProcessFile.bash+"t "+pathFile
    verifyFiles = os.system(monitoring)
    return verifyFiles 

def testCodeRetour():
  myPath = ProcessFile.returnPath()
Do you have any idea how it works?

Thank you for your help
If a list you want to return, then a list you must construct.

all_paths = []
for name in files:
    pathFiles = os.path.join(root, name)
    # OR: all_paths.extend(pathFiles)
return all_paths
That's because you are not returning a list. Line 21 overwrites your list with a single value. I expect you want to append that value to the list, not assign it to the same name.
nilamo likes this post
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Custom Function to Return Database Values rm78 0 192 Sep-05-2019, 01:01 PM
Last Post: rm78
  [SOLVED ]ValueError: View function did not return a response Hadad 0 805 Jul-24-2019, 04:01 PM
Last Post: Hadad
  List creation and return in Function leoahum 3 433 Mar-04-2019, 04:45 PM
Last Post: leoahum
  Function to return modified list Pjones006 2 398 Feb-06-2019, 10:57 PM
Last Post: Pjones006
  Function and return value Roh_80 1 450 Jan-24-2019, 03:15 PM
Last Post: buran
  how to use the return function NLittle17 5 715 Jan-08-2019, 12:01 AM
Last Post: ichabod801
  Use variable from one function in another without return P13N 3 538 Dec-25-2018, 05:57 PM
Last Post: stullis
  Making list empty after return in function dan789 10 1,169 Nov-24-2018, 11:54 PM
Last Post: micseydel
  My function won't return the sum unless the last paramater is an odd number. Maximuskiller78 1 511 Sep-29-2018, 03:11 AM
Last Post: ichabod801
  function wanted: resolve relative path Skaperen 4 631 Sep-06-2018, 01:52 AM
Last Post: Skaperen

Forum Jump:

Users browsing this thread: 1 Guest(s)