'Python dont execute class functions if param isnt set

I have a code like the following. Im iterating through files in a directory and try to read a number from the filename. I I wanna have it like: if there is a file with the required condition, i get the number from the name and set is in the path var. If the condition isnt met and there are no files i dont want to execute the functions of the class cause they are all dependant on the set path.

class Test():
    def __init__(self) -> None:
        num = get_num() # Can return None or Int
        if num:
            self.path = f"{num}_Test"

        # if i dont have a number, i dont have a path and dont want to execute the function

    def test(self) -> None:
        print(self.path)


testObj = Test()
testObj.test()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source