Python split with multiple parameters

   1932   1   0
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
It seems the python hou? split function only lets you to use one user defined delimiter like this:

Test = ('Divide this; more than, once.')
Test.split(';')
['Divide this', ' more than, once.']

but I can't define more than one delimiter like:

Test = ('Divide this; more than, once.')
Test.split(';|,')
['Divide this; more than, once.']

It doesn't split at all if I define more than one delimiter.

However, if I import ‘re’ and use that split function I can do:

 re.split(';|,', Test)
['Divide this', ' more than', ' once.']

So is it possible to use the ‘hou’ split function set for more than one delimiter? Or is that function have a limited capacity and I just need to import ‘re’ and use that one? (not that it's an issue, just wanting to get some clarification)
Edited by BabaJ - Nov. 15, 2019 19:03:44
User Avatar
Member
8535 posts
Joined: July 2007
Online
the split you are using belongs to string object and that's a standard Python object
so the difference between string.split and re.split is the same in houdini as outside of houdini using the same python version, so until string's split function supports multiple separators you can use re.split
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links