reading-notes

Software Development Reading Notes

View on GitHub

Classes and Objects

sample class and object:

class MyClass:
    variable = "blah"

    def function(self):
        print("This is a message inside the class.")

myobjectx = MyClass()
myobjecty = MyClass()

myobjecty.variable = "yackity"

# Then print out both values
print(myobjectx.variable)
print(myobjecty.variable)

output:

blah
yackity

access object functions using notation way:myobjectx.function()

Thinking Recursively in Python

"Problems (in life and also in computer science) can often seem big and scary. 
But if we keep chipping away at them, more often than not we can break them down into 
smaller chunks trivial enough to solve. This is the essence of thinking recursively."

Maintaining state

When dealing with recursive functions, keep in mind that each recursive call has its own execution context, so to maintain state during recursion you have to either:

Recursive data structures in Python

5 steps to train yourself thinking recursively

Pytest Fixtures

In testing, a fixture provides a defined, reliable and consistent context for the tests. This could include environment (for example a database configured with known parameters) or content (such as a dataset).

Fixtures define the steps and data that constitute the arrange phase of a test (see Anatomy of a test). In pytest, they are functions you define that serve this purpose. They can also be used to define a test’s act phase; this is a powerful technique for designing more complex tests.

The services, state, or other operating environments set up by fixtures are accessed by test functions through arguments. For each fixture used by a test function there is typically a parameter (named after the fixture) in the test function’s definition