How to separate name of the object from the suffix(.000)

How to separate name of the object from the suffix(.000) with python? I remeber there was some kind of “split” command…but I can’t remember its syntax.

If you know the extension length is always three characters preceded by a period:

>>> x = ‘object.000’
>>> x[ : -4]
‘object’

If you don’t know how many characters follow the period:

>>> x = ‘object.name.12345’
>>> periodPos = x.rfind(’.’)
>>> x[ : PeriodPos]
‘object.name’

… or the even shorter version:
>>> x = ‘object.name.12345’
>>> x[ : (x.rfind(’.’))]
‘object.name’

You can try:
namewithoutsuffix=nameoftheobject.split(’,’)[0]

I use it often and it works fine. But you cannot have a ‘.’ in the name, except in the suffix, or the result will be incorrect.

Skwerm,yes thanks I know that,but if “.000” is “.00” and there are alot of objects with different lenght fo the suffix, this wont work. There was some command to separate names from the “dot” symbol.
superrom, I’ll try your method right now…

Ahh, it works, great! Thanks superrom!

I edited my response above to show how to handle variable-length extensions. Also, using rfind() the objects can have periods in the name as well and will only chop off the characters following the last period in the string.

Yes, yes, I made it this way:

newName=current_weapon[found_weapon.name].getMesh().getName()[2:].split(‘.’)[0]
…and it works fine, thanks again.

I think that the edited version of the Skwerm’s answer is better, since it is more adaptative than mine. But if it works, for you, it’s ok.