I can't easily find out the exact size of the string I will produce. I only know the upper bound which should be within 1-2 characters of the final size. How do I shrink the string after filling it?
Based on your comment:

If you are trying to remove characters from your string use the .strip() method.
If you want the byte count of the string compared to the character count you need to change the encoding.
If you are just trying to remove the \0 character use the .replace() method.
Using the python C API, is it possible to shrink a PyUnicode object?