473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

A 'Box' Function

Hey guys.

I should warn you, first off, that I'm relatively new to Python.
Basically, what I'm trying to do is create a word-wrapping function
with the added complication that it add a character at the beginning
and end of each line, so that it encloses the text in a sort of 'box':

----------------
| Like this |
----------------

The word-wrapping function I'm working with is similar to the one given
here:
http://aspn.activestate.com/ASPN/Coo.../Recipe/148061

def wrap(text, width):
return reduce(lambda line, word, width=width: '%s%s%s' %
(line,
' \n'[(len(line)-line.rfind('\n')-1
+ len(word.split('\n',1)[0]
) >= width)],
word),
text.split(' ')
)

Does anyone have any ideas on how it could be modified? Am I
approaching it the right way? Thanks a bunch!

Mike

Apr 18 '06 #1
2 3229

<mi********@gmail.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com...
The word-wrapping function I'm working with is


I have never used this, but it might help you
import textwrap
dir(textwrap)

['TextWrapper', '__all__', '__builtins__', '__doc__', '__file__',
'__name__', '__revision__', '_whitespace', 'dedent', 'fill', 're',
'string', 'wrap']

tjr


Apr 18 '06 #2
mi********@gmail.com wrote:
Hey guys.

I should warn you, first off, that I'm relatively new to Python.
Basically, what I'm trying to do is create a word-wrapping function
with the added complication that it add a character at the beginning
and end of each line, so that it encloses the text in a sort of 'box':

----------------
| Like this |
----------------

The word-wrapping function I'm working with is similar to the one given
here:
http://aspn.activestate.com/ASPN/Coo.../Recipe/148061

Does anyone have any ideas on how it could be modified? Am I
approaching it the right way? Thanks a bunch!


Rather than rewriting wrap(), I would suggest wrapping it with a new
function, wrap_box(), that adds the header, line endings and trailer to
the lines returned from wrap().

Kent
Apr 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: mr_burns | last post by:
hi, using javascript, how do i select an option in a combo box? i have tried looking on the internet but dont really know what i should be searching for. what i want to happen is that when a...
7
by: Neil | last post by:
I have a check box on a form that's bound to a function that returns a True/False value. When the user clicks on the check box, I run some code through the MouseDown event. Everything works fine. ...
2
by: alan | last post by:
Hi all, I have create a simple function and make a pure C dll. When I use this DLL from my main program, I found I cannot see this function's definition tips (yellow box). It works fine, but no...
2
by: Microsoft News | last post by:
What I have is a message box that pops up. It is another browser window. The code is a general function that you pass message, title and a key to. The box works great except, that if you are on a...
2
by: Zlatko Matić | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
1
by: The Eclectic Electric | last post by:
I'd be very grateful if anyone could help me with this. From my limited knowledge of Javascript I don't think it is possible, but I'll punt anyway. I downloaded and very slightly adapted this...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
1
by: skyson2ye | last post by:
Hi, guys: I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem,...
4
by: sialater | last post by:
Hello, I realise there are a lot of topics related to this problem but many of what I have found has run cold or unresolved. What I have is an addressbook clone where there are groups which have...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.