Python Forum
How to split a String from Text Input into 40 char chunks?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to split a String from Text Input into 40 char chunks?
#5
(Jul-31-2023, 07:19 PM)Gribouillis Wrote:
(Jul-31-2023, 06:58 PM)lastyle Wrote: max 40 char packets which will be padded by spaces to have a readable resulting text.
It seems that you want the built-in textwrap module.
>>> import textwrap
>>> s = "The String is from a User Input and can be longer (between 1 and 290 Chars), but i Need to Split the String into max 40 char packets which will be padded by spaces to have a readable resulting text."
>>> print(textwrap.fill(s, width=40))
The String is from a User Input and can
be longer (between 1 and 290 Chars), but
i Need to Split the String into max 40
char packets which will be padded by
spaces to have a readable resulting
text.
>>> 

Thanks, that looks what i was searching for.
Reply


Messages In This Thread
RE: How to split a String from Text Input into 40 char chunks? - by lastyle - Jul-31-2023, 07:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Get the string after a specific char JanJan 5 441 Apr-30-2025, 05:04 AM
Last Post: snl_9527
  Unable to understand the function string.split() Hudjefa 8 2,668 Sep-16-2024, 04:25 AM
Last Post: Pedroski55
  Using string input for boolean tronic72 3 2,060 Nov-01-2023, 07:48 AM
Last Post: Gribouillis
  doing string split with 2 or more split characters Skaperen 22 6,439 Aug-13-2023, 01:57 AM
Last Post: Skaperen
  [split] Parse Nested JSON String in Python mmm07 4 2,826 Mar-28-2023, 06:07 PM
Last Post: snippsat
Question Take user input and split files using 7z in python askfriends 2 2,381 Dec-11-2022, 07:39 PM
Last Post: snippsat
  How to split the input taken from user into a single character? mHosseinDS86 3 2,200 Aug-17-2022, 12:43 PM
Last Post: Pedroski55
  is there an itertor of chunks? Skaperen 8 3,629 Jul-22-2022, 10:17 PM
Last Post: Skaperen
  Split string using variable found in a list japo85 2 2,200 Jul-11-2022, 08:52 AM
Last Post: japo85
  Editing text between two string from different lines Paqqno 1 1,858 Apr-06-2022, 10:34 PM
Last Post: BashBedlam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020