Preparing for ICT162 Python Exam - Auto Generate Class Template

In the previous semester, I was preparing for my semester exam for one of my Python programming modules, ICT162 Object-Oriented Programming. The duration of the exam was 3 hours.

However, it is an open book exam and I have to write Python codes and finish on time. In an open book exam, we are allowed to refer to our seminar notes and Python codes. Our screen will be monitored and recorded throughout the exam. In my understanding, as long it is not a socialising application, such as Telegram or Discord, we are fine.


I attempted the past year paper and solving those questions will take time. It took me 4-5 hours to complete a paper. As with any programming, if you rush it, you will encounter bugs and logical errors. Furthermore, the class diagram, functional and non-functional requirements were not explained clearly. My English stopped at N'level.

The more I practised on the past year paper, I begin to see a pattern where I wasted my time a lot. It was the writing of classes. The writing of def declaration. One class can have a few methods to declare, and there were more than 10 classes to create during the exam.

The writing of classes is the most time-consuming part of the exam. There's no time to correct them if something goes wrong.

As it was an open book exam, I figured out ways to make myself code faster. Any tools to complete it. The restriction for the exam is that the code must not include libraries except the ones mentioned by the question. Usually, those are built-in libraries such as, math and datetime.

So guess, there's no importing of dataclasses. It will result in zero marks. Every get/set method is being written manually. Time-consuming!

Writing the auto-class template generator

After careful consideration, I decided to automate the creation of the class template. This application will generate an empty class template based on the class diagram it reads.

The features are:

  1. Generate a class template.
  2. Identify @abstractmethod, @classmethod and @property decorators.
  3. Identify the instance variable and methods.
  4. Identify the class variable and methods.
  5. Identify the return value and type of each method.
  6. Generates set and get methods based on the class diagram.
  7. Include Python typehints.
  8. Respects the PEP 8 style.

Phew! That's kinda a lot to do for 3 hours exam, excluding programming the actual logic. I manage to get the tool running. I did not have the time to finish writing the tool with validation prompts.

Did my DIY tool make a difference?

Of course, it did. It took me 5 secs to copy and paste the generated output. It is faster compared to writing the wrong class template for 5 to 20 minutes while looking for errors.

I can focus more on writing the logic than making the class template. For example, the class diagram requires us to write the two classes and logic. The tool will generate the template based on the diagram.

Where's the code?

I have uploaded the code to my Github Gist page. I uploaded two, one without typehints and one with.

ICT162 Class Generator. To save time during the TOA exam.
ICT162 Class Generator. To save time during the TOA exam. -
ICT162 Class Generator with typehints. To save time during the TOA exam.
ICT162 Class Generator with typehints. To save time during the TOA exam. -
WIth TypeHints


I am able to answer all the questions and I got A+, 5.0 GPA for the paper.

  • Always prepare and study for your exam
  • Practice past year paper and see which part you are wasting your time.
  • Improvise it.
  • Create notes or tools to assist with your weakness

Study smart!