Metaprogramming

To my understanding, meta-programming is  not yet to the writing program to "write" program.
But it was given the great flexibility to manipulate the programs.

For basic metaprogamming, we can have some example to begin with.

# from http://python-3-patterns-idioms-test.readthedocs.io/en/latest/Metaprogramming.html
def howdy(self, you):
    print("Howdy, " + you)

MyList = type('MyList', (list,), dict(x=42, howdy=howdy))

ml = MyList()
ml.append("Camembert")
print(ml)
print(ml.x)
ml.howdy("John")

print(ml.__class__.__class__)

""" Output:
['Camembert']
42
Howdy, John
"""

留言

這個網誌中的熱門文章

AndrewNg's CNN notes(practical issues)

Confidence intervals & Credible intervals