Python Resources

Updated on July 16  2014

Python In Houdini Examples

Deborah R. Fowler

Python - General Examples (for Houdini specific examples click here)

Posted Feb 12  2014
Updated Dec 23  2017

NOTE: If you wish to know your python version:
import sys

Here is a simple script to handle file manipulation:

Problem: A student had generated some files caching out a simulation. Instead of typing the usual .bgeo.gz they accidently typed a comma instead of a period. As a result the files were not recognized since their format was then .bgeo. 

Solution: rename the files to .bgeo 

Here is the script:

import os
for filename in os.listdir( "." ):
    if filename.endswith( ",gz" ):
        os.rename( filename, filename[:-3] )

Here is another handy one for Windows users:

Problem: Needed to print out the names of the files in a directory.

Solution: run the following python script (2.7) (

import os
file = open("./list.txt","w")
for filename in os.listdir("."):
        print filename

Here is one related to the Renderfarm:

Renders from the farm are output.XXXX.exr, but if compiling multiple shots need unique names.

Solution: run the following python script (2.7) (

Here is on related to Houdini and Maya:

Problem: Bringing in a single frame of point data from Houdini into Maya:
in Maya to run Python open the script editor window at the bottom left MISSING IMAGEand select python tab. Load script (or type in a new one) and execute:

Solution: output the point data to a file.hclassic (ascii format) and then run the following script in maya (

file = open(“C:/Users/Deborah/Desktop/toMaya/untitled.hclassic”,”r”)

l = []

for line in file:

                for t in line.split():



                                except ValueError:


points = l[8:]


n = 1

tuples = []

for num in points:

                if (n % 4 != 0):


                n = n+1

print tuples


import maya.cmds as cmds

for n in range(0,len(tuples),3):



Problem: You want to mv all files that are evenly numbered into a directory.
A bit brute force, but does the job
if (f[-5:-4] == "0" or f[-5:-4] == "2" or f[-5:-4] == "4" or f[-5:-4] == "6" or f[-5:-4] == "8" ):

import os, shutil
path = "C:/Users/Deborah/Desktop/..../MyFiles/"
moveto = "C:/Users/Deborah/Desktop/...MyFiles/Evens/"
files = os.listdir(path)
for f in files:
    src = path+f
    dst = moveto+f
    if (f[-5:-4] in ["0","2","4","6","8"]):

: moving to a directory is
import os