Python SOP expanding $ Variable? nodesearch recursion depth?

   1028   1   1
User Avatar
Member
339 posts
Joined: June 2013
Online
Hey

Couple of questions about python.

A)
I'm working out helper functions for something that will be ran in a script so for ease of development seems to be faster to use the Python Shell to test simple commands and for bigger code to use something like Python SOP to write functions and test their calling.
Now, I've noticed that when trying to write a parameter with "$HIP/something", from Python Shell the parameter is written including the $Variable as is but when writing a parameter from a Python SOP I it gets expanded into its value. I also tried to use something like r"$HIP/something" without success.
I know with the Python SOP I can put an escape character "\$HIP/something" but from the Python Shell the "\" gets included, so I would like to find a way that works for both Python SOP AND the Python Shell. Unless there's a better way to test out scripting pieces in Houdini that I'm not aware of. I tried the Python Source Editor today and was not pleased to be honest, since it kept variables cached even after I deleted them from the editor. The other way around, purposefully expanding a variable in Python Shell I think I'm fine, by using hou.expandString().

B)
There's no way to decide the amount of recursion you want to go with something like nodesearch right? It's either traverse all the subchildren or not at all, right? Or maybe a way to filter into which nodes the recursion is expanded to.
https://www.sidefx.com/docs/houdini/hom/nodesearch.html [www.sidefx.com]
I would assume it would be the same for .recursiveGlob() ? https://www.sidefx.com/docs/houdini/hom/hou/Node.html [www.sidefx.com]

Thanks
Edited by probiner - Sept. 22, 2021 18:50:43
User Avatar
Member
339 posts
Joined: June 2013
Online
Thanks to @RPD and @IgorElovikov on discord for the workaround idea for the expanding string issue.

This will output /path/to/hip/folderin Python SOP and $HIPin the Python Shell.
var = "$HIP"
print var


But either of these will output $HIPin both Python Shell and Python SOP.
var = "$" + "HIP"
print var

var = "\x24HIP"
print var

Cheers
Edited by probiner - Sept. 23, 2021 10:07:50
  • Quick Links