Isinstance function confusion

I’ve checked W3Schools, and I think my syntax is correct, but I still get an error with the following code:
Edit: I should add that the error is TypeError: init() missing 1 required positional argument: “nomen” also, I expanded the code snippet to include the class definition.

Repl link:

class directory():
   def __init__(self,nomen): = nomen #makes the object searchable(nomen is Latin for name)
      self.contents = [] # lists all the files and folders in the directory
      self.sum = 0 #unused for now, will hold the sum of "size" of the contents
# x does get defined, I just didn't include that bit for the snippet
isinstance(x, directory))

Hi @ThomasWarenski did you resolve this? I didn’t get the error when I ran the code.

I did not resolve this, I am still getting the error code. I’ve attached a screenshot from Replot mobile to help.

the () shouldn’t be there after directory because that tries to create an instance of the class. You didn’t do that in the code snippet you showed.
Also please name the class Directory to conform to common conventions

1 Like

Thank you, I must have accidentally removed the open parenthese in the code snippet, which made it harder to catch I guess. Also, while I might not remember to use snake case for variable names, etc. I should remember to use pascal case for class names and the like. Thanks for the style guide link.

1 Like

Just pointing out that that’s Google style guide and is not official. The official conventions can be found in Python Enhancement Proposoal #8 (PEP8) here.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.