Daily Art 08-10-2016

Posts about working with TouchDesigner and using it in production environments
View All Tags






Rounding out some of our work here with Python is to look extensions. If you've been following along with other posts you've probably already looked over some extensions in this post. If you're brand new to this idea, check out that example first.
Rather than re-inventing the wheel and setting up a completely new example, let's instead look at our previous example of making a logger and see how that would be different with extensions as compared to a module on demand.
A warning for those following along at home, we're now knee deep in Python territory, so what' we'll find here is less specific to TouchDesigner and more of a look at using Classes in Python.
There are a number of ways that we might use modules on demand in TouchDesigner. Before we get too far along, however, we might first ask "what is a module on demand?"
According to the TouchDesigner wiki:
The MOD class provides access to Module On Demand object, which allows DATs to be dynamically imported as modules. It can be accessed with the mod object, found in the automatically imported td module.
Alternatively, one can use the regular python statement: import. Use of the import statement is limited to modules in the search path, where as the mod format allows complete statements in one line, which is more useful for entering expressions. Also note that DAT modules cannot be organized into packages as regular file system based python modules can be.
We've looked at dictionaries as data structures already, and have gotten a peak into how powerful then can be for storing and manipulating data. That's all well and good, but wouldn't it be lovely if we could loop through the contents of our dictionaries the same way we can loop through list items?
In fact, we can.