Hey there! I do have some good news for those who might care about my life: I have a rather large assignment due next week and I've just barely started it, even though it was assigned a week ago - there goes the spare time that I don't have!
This week, we have learned about scopes and namespaces. Our lecturer has done this by placing 'spam' strings by changing the value of a variable called 'spam' via the different scopes, which are local, non-local, and global. Local variables are usually created and accessed within the first 'occurrence' of a method header and its return value. Non-local variables are usually created and accessed within a superclass or the top most method if there are nested methods. Global variables are usually defined outside a method and it's made accessible to all methods defined in a class or in a Python file. I find this quite easy to understand, and it's self explanatory if you have practiced with it enough.
We have went deeper into testing our modules. We were re-introduced to unittest (assuming most of us came from CSC108), except to much further detail. We were made aware that there is a module called 'doctest', and in this module, there is a function called 'testmod', which will test all methods'/functions' docstring examples to see if we get the expected results. Instead of always relying on docstring examples to help us, there is a unittest module that we could use to test out a class. In order to use it, we have to use the TestCase class found inside the unittest module. Once we inherit this class, we write methods that will load up an instance of a class, and then we write code for each and every method or function and we have to see if we get an expected result. This is done by making an assertion, otherwise known as the keyword in Python, 'assert'. An assertion takes in a boolean statement then raises an exception which implies that we haven't written some method correctly. This class is useful if you wish to analyze a method thoroughly, step-by-step, however I personally find in most cases, we write 'small' programs, so the 'doctest' module usually suffices.
We have also touched up on our first assignment, the Tower of Anne Hoi (similar to the Tower of Hanoi), where a person is expected to move cheese blocks sequentially from stand to stand until you form a 'tower' where the cheese blocks go from smallest to largest from top to bottom. It was mainly just to show us recursion techniques in the program, but I do find this assignment to be a bit intimidating, or rather simply time consuming.
This will wrap up my blogging for this week, hopefully I can get this assignment done, especially with exams coming up as well in the same week!
No comments:
Post a Comment