Introduction: So far, I have used python as a full-blown programming language. Now I like to use it to write some notes (comments) with some calculations (python code) here and there (I actually use emacs and send the current buffer again and again to the ipython executable instance).
Problem: I like to reuse some common variable names, such as "A" or "d", several times in the same document, without triggering the problem that I accidentally forgot to reassign the value to one of these variable names.
I'm still abusing class statement
class _anon:
d = 10
A = d**2 * pi /4
class _anon:
A = d**2 * pi /4 # error is raised since d is missing
This works because the class statement creates an execution frame that works as the scope of the variable, but I wonder if there is syntax highlighted for this use case.
source
share