-3

I have written a module for teaching Python. I'd like to make it difficult for the smarter ones to view the source code as a short-cut. Does not need to be fully secure - disabling the inspect module might be enough - if this is possible.

In case this is useful to anyone else using Python3 for class tests etc here's what I've ended up doing (with thanks to wbwlkr).

python3 -OO -m py_compile testmod.py creates a file __pycache__/testmod.cpython-34.pyo Creating a symbolic link to this file named testmod.pyc means the code can't easily be inspected.

One other consideration is that sensitive local variables should be overwritten when not needed or they can be queried by locals()

  • I'm sorry, you want to **teach** [python|a programming language] *without showing code* ? – Rafalon Oct 04 '17 at 11:09
  • I want to **teach** Python, a programming language, using some code for interactive exercises. The daft _without showing code_ is your invention. – user7215682 Oct 08 '17 at 11:27
  • I didn't invent anything, I asked for clarification (that's what a question-mark usually means). I still don't fully understand though. You asked for a way to obfuscate your code, which means you want to **hide** at least part(s) of your code, right ? I'm just curious as I think if your students are good enough to **understand** the source code and then use it as a shortcut, it means to me they succeeded in learning what you want them to learn. But maybe I only see the tip of the iceberg – Rafalon Oct 08 '17 at 13:16
  • They are a mixed group (as is always the case with programming). Some are capable of looking under the hood and inspecting the code, others not at all. The idea is that simple tasks, seeded with different initial conditions, can be automatically assessed by having them write some code to generate a result and their answer is then tested by the obfusticated module. – user7215682 Oct 09 '17 at 14:48
  • Oh then you want to prevent *hardcoded* solutions ! It makes sense now :) – Rafalon Oct 09 '17 at 15:25
  • @user7215682 you may also be interested in checking out the [cseducators.se] community. It sounds like it might be up your alley. – Ben I. Dec 20 '17 at 14:48

1 Answers1

0

What you are searching for is a solution to "obfuscate" the source code of your module.

You could compile your module to byte-code, as suggested here : https://stackoverflow.com/a/7418341/8714367

wbwlkr
  • 189
  • 8