0

In this code, I am getting a path that is present in the base path, and it fetches the path correctly but the problem is that I want to save the function in another variable called hi but whenever I print it, it gives me the result None

import os
def contain(dirname, dPath):
    dirfiles = os.listdir(dirname)

    fullpaths = map(lambda name: os.path.join(dirname, name), dirfiles)
    dirs = []

    for file in fullpaths:
        if os.path.isdir(file): dirs.append(file)

    folder = list(dirs)
    watching = [s for s in folder if dPath in s]
    copy = str(watching)[2:-2]
    print(copy)

def hello():
    base = '/home/bilal/Videos/folder1'
    destination = '/home/bilal/Videos/folder1/fd'
    hi = contain(base, destination)
    print(f"This is another time: {hi}")
    
hello()
Sky wifibrand
  • 109
  • 1
  • 6

1 Answers1

2

It should be in this way:

import os
def contain(dirname, dPath):
    dirfiles = os.listdir(dirname)

    fullpaths = map(lambda name: os.path.join(dirname, name), dirfiles)
    dirs = []

    for file in fullpaths:
        if os.path.isdir(file): dirs.append(file)

    folder = list(dirs)
    watching = [s for s in folder if dPath in s]
    copy = str(watching)[2:-2]
    return copy#you need to return a value


def hello():
    base = '/home/bilal/Videos/folder1'
    destination = '/home/bilal/Videos/folder1/fd'
    hi = contain(base, destination)
    print(f"This is another time: {hi}")
    
hello()
SAI SANTOSH CHIRAG
  • 2,046
  • 1
  • 10
  • 26