473,387 Members | 1,542 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,387 software developers and data experts.

what module can do html encoder??

example:
s = ' ' --->  
Jul 18 '05 #1
2 1402
Leon wrote:
example:
s = ' ' --->  


That's technically not HTML encoding, that's replacing a perfectly valid
space character with a *non-breaking* space character. If that's all you
want to do, then:

s.replace(' ', ' ')

will do it. If, however, you wish to quote special HTML chars, like <, > and
&, then:

cgi.escape(s)

will do that for you. From the library reference for "escape(
s[, quote])":

Convert the characters "&", "<" and ">" in string s to HTML-safe
sequences. Use this if you need to display text that might contain such
characters in HTML. If the optional flag quote is true, the double-quote
character (""") is also translated; this helps for inclusion in an HTML
attribute value, as in <A HREF="...">.
Richard

Jul 18 '05 #2
richard wrote:
Leon wrote:
example:
s = ' ' ---> &nbsp;


That's technically not HTML encoding, that's replacing a perfectly valid
space character with a *non-breaking* space character.


How can you tell?

s = 'Â*' # non-breaking space
s = ' ' # normal space
s = 'á¿Ÿ' # em-space

But you might want to do something like:

def escapechar(s):
import htmlentitydefs
n = ord(s)
if n < 128:
return s.encode('ascii')
elif n in htmlentitydefs.codepoint2name:
return '&%s;' % htmlentitydefs.codepoint2name[n]
else:
return '&#%d;' % ord(s)

This requires unicode strings, because unicode encodings have multi-byte
characters. Demonstration:
f(u'ò') '&ograve;' f(u'ÅŸ') 'ş' f(u's')

's'

yours,
Gerrit Holl.

--
Weather in Lulea / Kallax, Sweden 13/12 10:20:
-15.0°C wind 0.9 m/s NNW (34 m above NAP)
--
In the councils of government, we must guard against the acquisition of
unwarranted influence, whether sought or unsought, by the
military-industrial complex. The potential for the disastrous rise of
misplaced power exists and will persist.
-Dwight David Eisenhower, January 17, 1961
Jul 18 '05 #3

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

Similar topics

3
by: Matt | last post by:
I'm trying to simply convert a .avi file recorded by our program to a wmv file, of course compressed as possible. I've looked at the examples provided by microsoft @...
0
by: Crisco www.misericordia.com.br | last post by:
Hi, friends! I am develop a simple encoder app, one form with one button that start the encoder. This is my code: ============================================================= Option...
9
by: Fred Yu | last post by:
Hi, I want to encode input text into html format such as replace "<" with "&lt", replace "&" with "&amp". Could you give me some ideas? Thanks. Fred
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.