Python re.split not working?

Python re.split not working?

Le_Bear
Collaborator Collaborator
2,909 Views
2 Replies
Message 1 of 3

Python re.split not working?

Le_Bear
Collaborator
Collaborator

Doing this in the console works:

>> line = '0.9;0.0028'
>>> arr = re.split(',|;',line)
>>> arr
['0.9', '0.0028']

but the same thing in code does not, as I get this value for arr

['0.9,0.0028']

I do import re in code, and don't see any error about re not being imported, so I am not sure what my problem is?

Thanks for any help.

Bernard

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
0 Likes
Accepted solutions (1)
2,910 Views
2 Replies
Replies (2)
Message 2 of 3

burzins
Participant
Participant
Accepted solution

Hi Bernard,

 

The code below gives me:

 

split.png

 

 

 

 

 

 

 

 

 

What does it do for you?

 

import adsk.core, adsk.fusion, adsk.cam, traceback
import re

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        line = '0.9;0.0028'
        arr = re.split(',|;',line)
        ui.messageBox(str(arr))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Steve

Message 3 of 3

Le_Bear
Collaborator
Collaborator

Yes, it's working fine. So my problem is somewhere else.I don't even know why I did not try a quick script to test as you suggested!

Found it! In fact I had a test on a string, before the split line, which was always false! So now it works just fine.
Thanks for pointing me on that small test.

Bernard

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
0 Likes