fixing stupid errors
This commit is contained in:
1 parent
22f3d9c762
commit
aaf329279a
2 files changed
+13
-9
No files matched your search
+9
-7
@@ -685,14 +685,16 @@ def lda_set_example_arg(inst, arg):
|
|||||||
" __init__ is a magic function that will run when you make a class instance"
|
" __init__ is a magic function that will run when you make a class instance"
|
||||||
|
|
||||||
LdaExampleClass = type(
|
LdaExampleClass = type(
|
||||||
"LdaExampleClass",
|
"LdaExampleClass", # name of class
|
||||||
(object,),
|
(object,), # inherit from who?
|
||||||
{
|
{
|
||||||
"__init__": lda_set_example_arg,
|
"__init__": lda_set_example_arg, # calling LdaExampleClass().__init__() would call lda_set_example_arg
|
||||||
"lda_example_class_arg": 1,
|
"lda_example_class_arg": 1, # a class property. it sticks to a class. not any instances.
|
||||||
"quadratic_builder": quadratic_builder,
|
"quadratic_builder": staticmethod(quadratic_builder),
|
||||||
"hello_world": hello_world,
|
"hello_world": staticmethod(hello_world),
|
||||||
"hello_to": hello_to,
|
"hello_to": staticmethod(
|
||||||
|
hello_to
|
||||||
|
), # so inst wont be passed in as first arg if i try lda1.hello_world() (the function dont take args)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -303,8 +303,10 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"it can be a number, a string, a list (not advised), or a function?\n",
|
"it can be a number, a string, a list (not advised), or a function?\n",
|
||||||
"\n",
|
"\n",
|
||||||
"for a function in a class it would be marked a classmethod (`@classmethod`) and with classmethods the instance get passed in first arg.\n",
|
"for a function in a class it would be marked a method and with methods the instance get passed in first arg. \n",
|
||||||
"`@staticmethod` used in the class block revert this behavior.\n",
|
"so non of these implicit `this` that is always there like in java. first param of a method is always the instance.\n",
|
||||||
|
"\n",
|
||||||
|
"`@staticmethod` will revert this behavior. no more instance passed in as first param.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"check the tutorial.py file im lazy\n"
|
"check the tutorial.py file im lazy\n"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in new issue
Block a user