How to remove suffix from a string?

Is it possible to remove suffix from a string?

For example. If i do something like this:

for obj in bpy.context.selected_objects:
if obj.type == “MESH”:

    print(obj.name)

i get this

Cube.002
Cube.001
Cube

How to tell python to remove suffix so I get
Cube
Cube
Cube

Cheers,
n1k

What about using “split()” method ?

originalString = "Cube.002"
strArray = originalString.split(".")
print(strArray[0])

Of course, you can get directly the wanted part :

originalString = "Cube.002"
print(originalString.split(".")[0])

you can as above
BUT

how do you expect python or the operating system or any program to know what one to use
you have 3 files with identical names
software is not magic it only dose what YOU instruct it to do

trying to have more than ONE file with the EXACT same name will cause major problems and even ERRORS and warnings about overwriting a file

It should probably be more like:

def strip_suffix(s):
    head, tail = s.rsplit(".")
    if tail.isnumeric():
        return head
    return s

strip_suffix(obj.name)

# "foo.bar" -> "foo.bar"
# "val.10e-5" -> "val.10e-5"
# "Cube.001" -> "Cube"
# "Cube.234" -> "Cube"

Hi guys. Thanks for the help I learned a lot from your examples and efficiently tackled problem in my script:)

Cheers,
n1k