Teaching Python using the My sCool Server

Teaching Python programming using the MSS

Python programming on the MSS

Programming in Python can be taught on the My sCool Server right out-of-the-box. It comes pre-installed with Python 2.7.x and Python 3.6.x. You may teach or practise via one of the following tools -
  1. Terminal
  2. IDLE (Integrated Development and Learning Environment)
  3. SciTE
Below are a few common to-dos that shall ease your experience of Python programming on the My sCool Server.

Terminal

Open a Terminal and activate the pre-configured virtual environment that contains several modules and libraries needed to teach Python at school.

For activating the Python 3.x virtual environment, execute :
  1. source /usr/local/share/msspython3/bin/activate
For activating the Python 2.x virtual environment, execute :
  1. source /usr/local/share/msspython2/bin/activate
Once done with the programming session, to exit, execute :
  1. deactivate
To explore more about Python virtual environments, a very powerful tool and concept, continue reading herein.

IDLE (Integrated Development and Learning Environment)

IDLE is Python’s Integrated Development and Learning Environment.

On the MSS, IDLE has been pre-configured to use the Python 3.x from the virtual environment. So you may start teaching and learning right away.

SciTE

SciTE is a SCIntilla based Text Editor. Originally built to demonstrate Scintilla, it has grown to be a generally useful editor with facilities for building and running programs.

Configuring SciTE for custom experience

SciTE has a lot of configuration settings, which are read from ~/.SciTEUser.properties (user-specific) and /usr/share/scite/SciTEGlobal.properties (global). Both of these files can be accessed from the Options menu of SciTE.

You may edit your user-specific ~/.SciTEUser.properties residing in your home directory via the SciTE Options -> Open User Options File menu option.

Herein below are given the two main custom settings that may be needed by every user. Those interested in further guidance and tips may visit this article.

Making Python 3.x the default in SciTE instead of Python 2.x

By default, SciTE is configured to use python i.e. Python 2.7.x to execute Python code. However, you may need to use python3 i.e. Python 3.6.x based on your curricular requirements. Don't worry as we have you covered.

Add the following lines to your ~/.SciTEUser.properties file -
  1. if PLAT_GTK
  2.     command.go.*.py=/usr/local/share/msspython3/bin/python3 -u "$(FileNameExt)"
  3.     command.build.SConscript=scons --up .
  4.     command.build.SConstruct=scons .
Preserve the indentation while copy/pasting or typing the above lines.

Now when using Tools -> Go the Python version used will be 3.x.

Executing Python programs requiring input via the command line

By default, SciTE requires executing a program needing manual inputs via the Terminal. However, it is possible to add an option to the Tools menu to invoke the execution via SciTE itself.

Add the following lines to your ~/.SciTEUser.properties file -
  1. if PLAT_GTK
  2.     command.name.0.*.py=Go in Terminal
  3.     command.0.*.py=mate-terminal -x sh -c "\
  4. $(command.go.*.py);\
  5. echo;\
  6. read -p 'Hit enter to close ...' x\
  7. "
Preserve the indentation while copy/pasting or typing the above lines.

Now you shall see Tools -> Go in Terminal option. Use this when executing programs that need a manual input.

Those interested in digging deep into this customisation and its limitations may refer this excellent document.

Installing additional Python modules

There may be a need to install additional Python modules to teach / learn advanced concepts. This can only be done by a teacher or admin who has access to the mssadmin credentials.

Herein is an example showing how one may install the mysql-connector module in the Python 3.x virtual environment while being logged into a MSS client -
  1. ssh mssadmin@server
  2. sudo su -
  3. cd /usr/local/share/msspython3/
  4. source bin/activate
  5. pip install mysql-connector
  6. deactivate
Explanation of the above steps :
Step 1:  Login to the admin account onto the MSS. Enter mssadmin's password when prompted.
Step 2:  Become superadmin on the MSS. Enter mssadmin's password when prompted.
Step 3: Navigate to the Python 3.x virtual environment directory
Step 4: Activate the virtual environment
Step 5: Install the mysql-connector module
Step 6: Deactivate and exit the virtual environment