Class as Syntactic Sugar of Functions in Python

More explanation coming up, but essentially I’ve tried to define classes with functions in Python for a couple times already, but this time I have something that looks pretty good.

To use it, you just have to provide the class name and instance variables and methods:

make_class(
<class_name>, 
{'__init__': <...>, 'instance_variable_or_method': <...>})

Essentially I used decorators to allow users to define functions that take in self as the first argument but call those functions without self. Also note, the init doesn’t have to return anything just like regular Python. The client code starts at line 22.

Screen Shot 2019-04-08 at 12.39.18 AM.png

 
0
Kudos
 
0
Kudos

Now read this

Generate Programs from Spreadsheets

The other day, my friend told me his product manager often times have trouble translating his financial models in spreadsheet to code, so he can test his ideas on larger datasets, because he is the one that has to come up with the... Continue →