Search - User list
Full Version: Python split with multiple parameters
Root » Technical Discussion » Python split with multiple parameters
BabaJ
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)
tamte
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
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB