eduardo simioni

Tag: reference

Python, modules and static objects

by on Jan.17, 2014, under python, Uncategorized

There’s this little caveat about python I recently learned that would have helped me understand some of its concepts much more clearly if I was told this earlier on:

A module is a static object.

That means, and please someone correct me if I’m wrong, but maybe with the exception of global variables (which you should avoid anyway), you can treat a module as a static object. So instead of creating a static class for some tool functions you can just group all those functions into a separate .py.

One of the best things in python is how easy and robust is to work with modules, do take your time to get to know how they work. It will help tons to organize your tools and re-use code.

Another thing to remember: __init__.py is used by the python interpreter to treat directories as packages. And a must read literature on the subject is Python documentation on Modules.

Leave a Comment :, , , , , more...

reading/writing xml with python and maxscript

by on Mar.09, 2011, under pipeline

If you know where to find the information it becomes quite straight forward if you are not doing anything complex. With python you can use xml.dom.minidom, while with maxscript you can use either .NET Object “System.Xml.XmlDocument” or Class “System.Xml.XmlReader“.

With python you create a root element and append child elements from there. A very good sample can be found on: http://www.postneo.com/projects/pyxml/ To read you have getElementsByTagName on both python and dotnet XmlDocument. XmlReader might be a bit faster, but you have to parse elements by yourself.

There’s an issue with minidom’s toprettyprintxml, it adds whitespace and tabs between tags, around textNodes. And they are obviously read afterwards. A couple of different solutions are discussed on Ron Rothman’s blog, the easiest one using xml.dom.ext.PrettyPrint.

Leave a Comment :, , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!