python 3.x - After so many chars in a string, find the nearest space and put it on a new line -


i'm trying make tidy in file i'm having problem. asking details , if more 27 bytes long need find nearest previous space , put on new line.

(using python 3.2)

i starting this:

details = input ("details: ") delen = len(details) if delen >27:     #code here else:     pass 

is possible? if give me hand please?

cheers

str.rfind friend.

details = input ("details: ") if len(details) > 27:     nearest_space = details.rfind(' ', 0, 27)     first, second = details[:nearest_space], details[nearest_space:] else:     first, second = details, none 

note rfind raise exception if no space found in details.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -