LogFAQs > #960238115

LurkerFAQs, Active DB, DB1, DB2, DB3, DB4, DB5, DB6, DB7, Database 8 ( 02.18.2021-09-28-2021 ), DB9, DB10, DB11, DB12, Clear
Topic List
Page List: 1
TopicITT: Learning Python
1337toothbrush
11/22/21 9:17:08 AM
#429:


The "self" keyword is a way to reference the object itself. This is so that Python knows that you want to reference the object itself (as opposed to a global or function variable). Let me break down what you're doing with the key line: self.extra_privileges = Privilege(self)

Privilege(self) is a call to Privilege's __init__ function, the first parameter of which is self. The __init__ function is special because it indicates how you want objects of that class to be initialized, therefore the self parameter is required so that you can add all the attributes. HOWEVER, this is a parameter that Python automatically passes to that function call. What you're doing here is passing Admin's self, so here's how your function call is really working:

self.extra_privileges = Privilege(Privilege's self, Admin's self)

If you do this: self.extra_privileges = Privilege()
It's really calling: self.extra_privileges = Privilege(Privilege's self)

But you're missing the second parameter (which is privileges)

Since you are assigning privileges to a fixed value, you're not actually using the privileges parameter in __init__ anyway, so you can get rid of that.

---
... Copied to Clipboard!
Topic List
Page List: 1