O'Reilly logo

Python Recipes Handbook: A Problem-Solution Approach by Joey Bernard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© Joey Bernard 2016

Joey Bernard, Python Recipes Handbook, 10.1007/978-1-4842-0241-8_8

8. Metaprogramming

Joey Bernard

(1)Fredericton, New Brunswick, Canada

One of the key mantras in programming is to not repeat yourself. Whenever you do the same task more than once, you should take a look at it to see if there is any way to automate it. This is the primary reason for writing programs. But this applies equally to the task of writing the code itself. If you are repeating chunks of code, you should step back to see if there is some better way of achieving the same result.

One technique available to deal with this issue is metaprogramming. Essentially, metaprogramming is code that affects other code. The usual way this is done within Python is either ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required