Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change '>' to '>' and '>' to '>'? [duplicate]

Tags:

python

print u'<'

How can I print <

print '>' 

How can I print &gt;

like image 472
zjm1126 Avatar asked Dec 30 '09 01:12

zjm1126


People also ask

How do you change a variable to a string?

We can convert numbers to strings through using the str() method. We'll pass either a number or a variable into the parentheses of the method and then that numeric value will be converted into a string value. The quotes around the number 12 signify that the number is no longer an integer but is now a string value.

How do you change a string to a type in Python?

In Python an integer can be converted into a string using the built-in str() function. The str() function takes in any python data type and converts it into a string.

What is &lt in Python?

Save this answer. Show activity on this post. &lt; stands for lesser than (<) symbol and, the &gt; sign stands for greater than (>) symbol .


1 Answers

You should use HTMLParser module to decode html:

>>> import HTMLParser
>>> h= HTMLParser.HTMLParser()
>>> h.unescape('alpha &lt; &beta;')
u'alpha < \u03b2'

To escape HTML, cgi module is fine:

>>> cgi.escape(u'<a>bá</a>').encode('ascii', 'xmlcharrefreplace')
'&lt;a&gt;b&#225;&lt;/a&gt;
like image 79
jbochi Avatar answered Oct 18 '22 22:10

jbochi