-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_code.py
94 lines (73 loc) · 2.69 KB
/
example_code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
This file is an example and guide on how code should be structured in our
project.
"""
from random import random # Do *not* use from ... import *
CONSTANT_VALUE_UPPERCASE_UNDERSCORES = 0
"""
This is a constant value and should not be changed by any code. If this value
should be used for some means of configuration consider moving it to one of the
existing configuration files
"""
class ClassNameInCapWords:
"""
This class contains several methods with their corresponding access
permissions
"""
def __init__(self, public_property):
"""
init
"""
self.public_property = public_property
"""
This property (or attribure) is public and can be accessed by
anyone.
"""
def method_names_with_underscores(self, first_param, second_param,
optional_param=None):
"""
This method is accessible by everyone.
Parameters
----------
first_param : string
This is the first parameter. It will be used for some purpose.
second_param : int
The second parameter will be used for some other purpose
optional_param : list or None, optional
This parameter might be present or not. It defaults to None
:rtype: list of ClassNameInCapWords
"""
print(self, first_param, second_param, optional_param)
return []
def _protected_method(self):
"""
This method should not be accessed outside this object, but you can.
Any classes that inherits from `ClassNameInCapWords` can access this
method normally.
"""
return self
def __private_method(self):
"""
This method should **not** be accessed outside its object and it can
not be accessed normally - even by inheriting classes. But it is
still possible to access this method via
`_ClassNameInCapWords__private_method`. The content of this
docstring is not shown in the built documentation.
"""
print(random.random(10))
return self
def add(self, right_side):
"""
This methods returns the sum of public_property and b.
right_side : int
The right part of the sum
:rtype: int
.. doctest::
>>> from example_code import ClassNameInCapWords
>>> obj = ClassNameInCapWords(1)
>>> obj.public_property
1
>>> obj.add(1)
2
"""
return self.public_property + right_side