Considering that booleans are mostly used in coditions, the second way seems most appropriate.
o = MyClass()
...
if o.is_request: # very intuitive
# it's a request
質問
Coding style question: What is the recommended way of naming flag class attributes, i.e. attributes being True
or False
. Styles I can think of are:
class MyClass:
def my_method(self):
self.request = False
class MyClass:
def my_method(self):
self.is_request = False
class MyClass:
def my_method(self):
self.request_flag = False
PEP8 does not seem to give a firm recommendation. Is there a canonical way of doing this?
解決
Considering that booleans are mostly used in coditions, the second way seems most appropriate.
o = MyClass()
...
if o.is_request: # very intuitive
# it's a request