Blog Post #3: Code Type Snippets ๐Ÿ‘จโ€๐Ÿ’ป

DebadityaPal
Published: 07/15/2021

So we have just passed the halfway mark on our GSoC journey and a considerable amount of my project is over. However, now is not the time to rest. Now comes the most important part of my project, i.e: Code Type Snippets. It is this feature that is going to encourage and entertain users the most so that they keep on using my package.

The idea is to let the users write Python code during runtime while a course is being served, and check that code for correctness. So in a manner my program will have another program running inside of it. Sort of like a shell inside a shell. Shellception! but how would we do this?

Turns out Python already has an inbuilt module for it called code. So this code module has a few classes like the InteractiveConsole class that closesly emulates the actual interactive Python Shell experience and takes in user code. This code is stored as a string, we have the InteractiveInterpreter.runcode() function for running this code and generating the variables dynamically at runtime.

So for now I have planned to use these for the CodeType snippets as I can use a simple string matching to check for code correctness, and later run the code to keep the variables ready for the next Code Snippet within the same chapter.
DJDT

Versions

Time

Settings from gsoc.settings

Headers

Request

SQL queries from 1 connection

Static files (2312 found, 3 used)

Templates (11 rendered)

Cache calls from 1 backend

Signals

Log messages