I am working with python3
and am just starting to learn about dataclass
I am trying to create a dataclass having an attribute that is list of itself.
Something like:
@dataclass
class Directory:
name: str = field(default_factory=generate_randomly)
num_of_files: int = 0
...
subdirectories: List[Directory] = []
What I am struggling with is how to define the subdirectories
attribute which is a List of Directory itself
If I try this
dir1 = Directory('folder1')
dir2 = Directory('folder2')
dir = Directory(subfolders=[dir1, dir2])
Traceback (most recent call last):
File "main.py", line 14, in <module>
class Directory:
File "main.py", line 17, in Directory
subfolders: List(Directory) = []
NameError: name 'Directory' is not defined
I saw one post here but that doesn't look like what I need