I have a dummy text with numerous lengths.
sample_text = """Nunc tempus metus sem, at posuere nulla volutpat viverra. Sed nec nisl imperdiet, egestas ex et, sodales libero. Suspendisse egestas id dui at aliquet. Nulla a justo neque. Pellentesque non urna iaculis, maximus dolor at, pellentesque eros. Duis mi velit, ornare eu mollis sed, congue eget nisl. Ut suscipit, elit eu mattis vehicula, justo quam vulputate urna, nec tempor augue ligula sed nisl. Phasellus vel augue eu nibh sodales pretium ornare vel felis.Vivamus vitae suscipit orci. """
I am finding a way to justify the text like right alignment. Went through the text wrap docs but it's justified only default left.
import textwrap
wrapper = textwrap.TextWrapper(width=50)
dedented_text = textwrap.dedent(text=sample_text)
print(wrapper.fill(text=dedented_text))
Text wrap provies also many features like shortener, indent etc.
Found another way to justify the text.
str.ljust(s, width[, fillchar])
str.rjust(s, width[, fillchar])
str.center(s, width[, fillchar])
But the above function only works when text len is shorter than width.
Is there any function like above or way to justify the text?
docxhave to do with this? I believe OP is asking about simple strings...