[python][maya] rstrip() being odd

trying to strip the ‘.ma’ extension form filenames
…but why is this happening?

name='outfit.ma'
sname=name.rstrip('.ma')
print (sname)
name='uniform.ma'
sname=name.rstrip('.ma')
print (sname)
outfit
unifor

It chews up the final ‘m’ on ‘uniform.ma’…

nevermind, I didn’t understand rstrip()…it’s doing exactly what I’m telling it to. I need to go home.

sname=name.split('.')[-2]

does what I need

source.rstrip(given) will use each character of the given string and strip the source from right.


'uniform.ma'.rstrip('.ma')  # will strip ., m, a individually so you are left with unifor
>>> 'unifor'
'outfit.ma'.rstrip('.ma')
>>> 'outfit'
'mama.ma'.rstrip('.ma')  # will strip ., m, a individually which leaves you nothing
>>> ''

thanks. nice blog, by the way.

Thanks…

You could also use os.path.splitext:

>>> name = 'uniform.ma'
>>> os.path.splitext(name)
('uniform', '.ma')
>>> os.path.splitext(name)[0]
'uniform'

os.path.splitext() looks like the exact thing I need.