This is mostly a review of the style.
Python has an official style-guide, PEP8.
It recommends using lower_case
for variable and function names and PascalCase
for class names.
It also recommends using whitespace in the following way:
After function and class definitions, two blank lines.
Between class methods, one blank line.
To separate code blocks within a function/method, one blank line.
operators should be surrounded by whitespace (so
idx += 1
), except when used as a keyword in a function-call (sof(a=1, b=2)
). Commas are also followed by a space.
Python has comments, they start with a #
. PEP8 recommends using two spaces after code (before the #) and one space after the #.
Examples:
# Normal, full line comment
some_code.action() # Does some cool stuff
Python also has docstrings, which serve to document code. The whole module, classes and functions/methods can take docstrings. They are described in PEP257.
They should look like this:
class A(object):
"""A normal class"""
def __init__(self, *args):
"""
The constructor
Does some fancy stuff with `args`
"""
self.args = args
As you can see, you can use multi-line strings. The indentation of the first line will be removed from the string.
You can access these strings e.g. by looking at the dunder __doc__
attribute (so A.__doc__ == "A normal class"
) or by using help(A.__init__)
in an interactive shell. Also, a lot of documentation tools will pick up on this.
So, all your strings within the methods should be comments and start with #
.
All your strings directly above methods should be docstrings and be inside the methods (as the first line).
In addition to these comments, you should also use the if __name__ == "__main__":
if __name__ == "__main__":
guard, which allows importing your code from other scripts.
This is mostly a review of the style.
Python has an official style-guide, PEP8.
It recommends using lower_case
for variable and function names and PascalCase
for class names.
It also recommends using whitespace in the following way:
After function and class definitions, two blank lines.
Between class methods, one blank line.
To separate code blocks within a function/method, one blank line.
operators should be surrounded by whitespace (so
idx += 1
), except when used as a keyword in a function-call (sof(a=1, b=2)
). Commas are also followed by a space.
Python has comments, they start with a #
. PEP8 recommends using two spaces after code (before the #) and one space after the #.
Examples:
# Normal, full line comment
some_code.action() # Does some cool stuff
Python also has docstrings, which serve to document code. The whole module, classes and functions/methods can take docstrings. They are described in PEP257.
They should look like this:
class A(object):
"""A normal class"""
def __init__(self, *args):
"""
The constructor
Does some fancy stuff with `args`
"""
self.args = args
As you can see, you can use multi-line strings. The indentation of the first line will be removed from the string.
You can access these strings e.g. by looking at the dunder __doc__
attribute (so A.__doc__ == "A normal class"
) or by using help(A.__init__)
in an interactive shell. Also, a lot of documentation tools will pick up on this.
So, all your strings within the methods should be comments and start with #
.
All your strings directly above methods should be docstrings and be inside the methods (as the first line).
In addition to these comments, you should also use the if __name__ == "__main__":
guard, which allows importing your code from other scripts.
This is mostly a review of the style.
Python has an official style-guide, PEP8.
It recommends using lower_case
for variable and function names and PascalCase
for class names.
It also recommends using whitespace in the following way:
After function and class definitions, two blank lines.
Between class methods, one blank line.
To separate code blocks within a function/method, one blank line.
operators should be surrounded by whitespace (so
idx += 1
), except when used as a keyword in a function-call (sof(a=1, b=2)
). Commas are also followed by a space.
Python has comments, they start with a #
. PEP8 recommends using two spaces after code (before the #) and one space after the #.
Examples:
# Normal, full line comment
some_code.action() # Does some cool stuff
Python also has docstrings, which serve to document code. The whole module, classes and functions/methods can take docstrings. They are described in PEP257.
They should look like this:
class A(object):
"""A normal class"""
def __init__(self, *args):
"""
The constructor
Does some fancy stuff with `args`
"""
self.args = args
As you can see, you can use multi-line strings. The indentation of the first line will be removed from the string.
You can access these strings e.g. by looking at the dunder __doc__
attribute (so A.__doc__ == "A normal class"
) or by using help(A.__init__)
in an interactive shell. Also, a lot of documentation tools will pick up on this.
So, all your strings within the methods should be comments and start with #
.
All your strings directly above methods should be docstrings and be inside the methods (as the first line).
In addition to these comments, you should also use the if __name__ == "__main__":
guard, which allows importing your code from other scripts.
This is mostly a review of the style.
Python has an official style-guide, PEP8.
It recommends using lower_case
for variable and function names and PascalCase
for class names.
It also recommends using whitespace in the following way:
After function and class definitions, two blank lines.
Between class methods, one blank line.
To separate code blocks within a function/method, one blank line.
operators should be surrounded by whitespace (so
idx += 1
), except when used as a keyword in a function-call (sof(a=1, b=2)
). Commas are also followed by a space.
Python has comments, they start with a #
. PEP8 recommends using two spaces after code (before the #) and one space after the #.
Examples:
# Normal, full line comment
some_code.action() # Does some cool stuff
Python also has docstrings, which serve to document code. The whole module, classes and functions/methods can take docstrings. They are described in PEP257.
They should look like this:
class A(object):
"""A normal class"""
def __init__(self, *args):
"""
The constructor
Does some fancy stuff with `args`
"""
self.args = args
As you can see, you can use multi-line strings. The indentation of the first line will be removed from the string.
You can access these strings e.g. by looking at the dunder __doc__
attribute (so A.__doc__ == "A normal class"
) or by using help(A.__init__)
in an interactive shell. Also, a lot of documentation tools will pick up on this.
So, all your strings within the methods should be comments and start with #
.
All your strings directly above methods should be docstrings and be inside the methods (as the first line).
In addition to these comments, you should also use the if __name__ == "__main__":
guard, which allows importing your code from other scripts.
This is mostly a review of the style.
Python has an official style-guide, PEP8.
It recommends using lower_case
for variable and function names and PascalCase
for class names.
It also recommends using whitespace in the following way:
After function and class definitions, two blank lines.
Between class methods, one blank line.
To separate code blocks within a function/method, one blank line.
operators should be surrounded by whitespace (so
idx += 1
), except when used as a keyword in a function-call (sof(a=1, b=2)
). Commas are also followed by a space.
Python has comments, they start with a #
. PEP8 recommends using two spaces after code (before the #) and one space after the #.
Examples:
# Normal, full line comment
some_code.action() # Does some cool stuff
Python also has docstrings, which serve to document code. The whole module, classes and functions/methods can take docstrings. They are described in PEP257.
They should look like this:
class A(object):
"""A normal class"""
def __init__(self, *args):
"""
The constructor
Does some fancy stuff with `args`
"""
As you can see, you can use multi-line strings. The indentation of the first line will be removed from the string.
You can access these strings e.g. by looking at the dunder __doc__
attribute (so A.__doc__ == "A normal class"
) or by using help(A.__init__)
in an interactive shell. Also, a lot of documentation tools will pick up on this.
So, all your strings within the methods should be comments and start with #
.
All your strings directly above methods should be docstrings and be inside the methods (as the first line).
In addition to these comments, you should also use the if __name__ == "__main__":
guard, which allows importing your code from other scripts.
This is mostly a review of the style.
Python has an official style-guide, PEP8.
It recommends using lower_case
for variable and function names and PascalCase
for class names.
It also recommends using whitespace in the following way:
After function and class definitions, two blank lines.
Between class methods, one blank line.
To separate code blocks within a function/method, one blank line.
operators should be surrounded by whitespace (so
idx += 1
), except when used as a keyword in a function-call (sof(a=1, b=2)
). Commas are also followed by a space.
Python has comments, they start with a #
. PEP8 recommends using two spaces after code (before the #) and one space after the #.
Examples:
# Normal, full line comment
some_code.action() # Does some cool stuff
Python also has docstrings, which serve to document code. The whole module, classes and functions/methods can take docstrings. They are described in PEP257.
They should look like this:
class A(object):
"""A normal class"""
def __init__(self, *args):
"""
The constructor
Does some fancy stuff with `args`
"""
self.args = args
As you can see, you can use multi-line strings. The indentation of the first line will be removed from the string.
You can access these strings e.g. by looking at the dunder __doc__
attribute (so A.__doc__ == "A normal class"
) or by using help(A.__init__)
in an interactive shell. Also, a lot of documentation tools will pick up on this.
So, all your strings within the methods should be comments and start with #
.
All your strings directly above methods should be docstrings and be inside the methods (as the first line).
In addition to these comments, you should also use the if __name__ == "__main__":
guard, which allows importing your code from other scripts.
This is mostly a review of the style.
Python has an official style-guide, PEP8.
It recommends using lower_case
for variable and function names and PascalCase
for class names.
It also recommends using whitespace in the following way:
After function and class definitions, two blank lines.
Between class methods, one blank line.
To separate code blocks within a function/method, one blank line.
operators should be surrounded by whitespace (so
idx += 1
), except when used as a keyword in a function-call (sof(a=1, b=2)
). Commas are also followed by a space.
Python has comments, they start with a #
. PEP8 recommends using two spaces after code (before the #) and one space after the #.
Examples:
# Normal, full line comment
some_code.action() # Does some cool stuff
Python also has docstrings, which serve to document code. The whole module, classes and functions/methods can take docstrings. They are described in PEP257.
They should look like this:
class A(object):
"""A normal class"""
def __init__(self, *args):
"""
The constructor
Does some fancy stuff with `args`
"""
As you can see, you can use multi-line strings. The indentation of the first line will be removed from the string.
You can access these strings e.g. by looking at the dunder __doc__
attribute (so A.__doc__ == "A normal class"
) or by using help(A.__init__)
in an interactive shell. Also, a lot of documentation tools will pick up on this.
So, all your strings within the methods should be comments and start with #
.
All your strings directly above methods should be docstrings and be inside the methods (as the first line).
In addition to these comments, you should also use the if __name__ == "__main__":
guard, which allows importing your code from other scripts.