Macro like functionality for shorthand variable names

Tilman Kispersky tilmaniac at gmail.com
Fri Jun 6 23:13:16 CEST 2008


I have python code in a class method translated from C++ that looks
sort of like this:

>>>  self.dydt[1] = self.a * (self.b * self.y[0] - self.y[1])


To make this more readable in C++ I had made macros to achieve this:
#define du (dydt[1])
#define u (y[1])
#define V (y[0])

du = a * (b * V - u);


I realize the value of not having macros in Python.  They've tripped
me up more than once in C++.  My question is:
Is there any way to write a shorterhand more readable version of the
python code above?  I'm doing several calculations one after the other
and some of the lines are quite long.



More information about the Python-list mailing list