Jump to content

Wrapping words in Python [Help?]

- - - - -

  • Please log in to reply
4 replies to this topic

#1
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 554 posts
  • Location:/etc/passwd
I hope I spelt the title right (Firefox is saying I spelt "spelt" wrong :D)- I put in [help] to indicate I was asking not giving a tut.

So anyway here is my problem:
I have a Python application that is chopping words in half at the end of each line. This is REALLY annoying. (Especially when I'm speed reading reports). So how can I make it shift the ENTIRE word on to the next line?


Thanks
Bbqroast

And yes Google is my friend :D
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#2
brownhead

brownhead

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
Do you mind posting the code?

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
I believe Python has a standard library function named "wrap":
7.7. textwrap ? Text wrapping and filling — Python v2.7.1 documentation

Also, spelt is not standard American English if I recall, so it says it is wrong. it is correct though: "verb, spelled or spelt, spellĀ·ing."
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 554 posts
  • Location:/etc/passwd
Thanks...
Do you know any friendly user guides for that???
It seems a bit complex.
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
That is a friendly guide, I would recommend you get used to the Python document format so you may get more out of reading them when you need to know a function. You will notice the function is defined like this:
    wrap(text, width);

So you will need to input your text in the first parameter, and the desired width of the column of text.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users