human
Can you show me a Python code to truncate spaces in strings.
assistant
Here is a Python code to truncate spaces in strings

import string

def truncate(text, max_length):
    """Truncate a string to a maximum length.

    :param str text:
    :param int max_length:
    :rtype: str
    :return:
    """
    if len(text) > max_length:
        return text[:max_length]
    else:
        return text

# Enter the string
text = "This is a long string"

# Calling the function
print((truncate(text, 10)))

#Example Output
# This is a 

#Remember to inspect code for bugs.