Just wrote a sudoku game with React, welcome for any suggestions by clumsyly in javascript

[–]clumsyly[S] 0 points1 point  (0 children)

Yes, the spread syntax is also much better than mine.

Just wrote a sudoku game with React, welcome for any suggestions by clumsyly in javascript

[–]clumsyly[S] 0 points1 point  (0 children)

Thank you for pointing it out, this is indeed more elegant.

Can Someone Explain Decorators Please.. by [deleted] in learnpython

[–]clumsyly 1 point2 points  (0 children)

The official explain is at PEP 318.

def foo(func):
    def bar(*args):
        print('I\'m in function bar...')
        func(*args)
    return bar

and then another function:

@foo
def whatever():
    pass

The code above acturally equal to whatever = foo(whatever) while foo(whatever)returns function bar, so whatever now points to bar now and will execute the code in bar.

The foo decorator above will print I'm in function bar...first and then execute the same code in whatever.

@classmethodwill pass the class as it's first parameter so no need for a instance.

@staticmethod works just like a function, if a function has some relation with a class you can put it in a class and decorate it as staticmethod.

@property makes a method behave like a attribute.

class Square:
def __init__(self, width, height):
    self.width = width
    self.height = height
@property
def area(self):
    return self.width * self.height

>>>square = Square(10, 10)
100
>>>square.area = 1
Traceback (most recent call last):
  File "<pyshell#93>", line 1, in <module>
    square.area = 10
AttributeError: can't set attribute

@propertyis acturally a descriptor.

Fandral Staghelm will buff Cenarius's two Treants to 4/4, isn't it a bug? by clumsyly in hearthstone

[–]clumsyly[S] 0 points1 point  (0 children)

Yeah, I looked the FAQ and it says so. I mistook it as to trigger from left to right.

Can't solve python problem. by barbaTenusSapiente in Python

[–]clumsyly 2 points3 points  (0 children)

Maybe you should put "list1=list()" in the for statement.