<div>&nbsp;</div>
<div>&nbsp;</div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user = User.objects.get(userID__exact=user_id)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user.blog_set.all()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blogData = user.blog_set.get(id__exact=<a href="http://user.id">user.id</a>)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; section_list = blogData.section_set.all
()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; latest_content_list = blogData.content_set.all().order_by(&#39;-pub_date&#39;)[:5]</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blog = dict()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blog[&#39;currentPost&#39;] = {&quot;dateIndex&quot;:0, &quot;postIndex&quot;:0}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blog[&#39;title&#39;] = blogData.name.encode(&#39;utf-8&#39;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blog[&#39;description&#39;] = blogData.description.encode(&#39;utf-8&#39;)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sections = list()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for section in section_list:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sections.append({&quot;title&quot;:section.name.strip(), &quot;link&quot;:&quot;<a href="http://www.hideout.com.br/">www.hideout.com.br
</a>&quot;})<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blog[&#39;sections&#39;] = sections</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; links = list()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; link = dict()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; links.append({&quot;title&quot;:user_id, &quot;link&quot;:&quot;<a href="http://www.hideout.com.br/">www.hideout.com.br</a>&quot;})<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; links.append({&quot;title&quot;:&quot;hideout&quot;, &quot;link&quot;:&quot;
<a href="http://www.hideout.com.br/">www.hideout.com.br</a>&quot;})<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; links.append({&quot;title&quot;:&quot;hideout&quot;, &quot;link&quot;:&quot;<a href="http://www.hideout.com.br/">www.hideout.com.br</a>&quot;})
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; links.append({&quot;title&quot;:&quot;hideout&quot;, &quot;link&quot;:&quot;<a href="http://www.hideout.com.br/">www.hideout.com.br</a>&quot;})</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blog[&#39;links&#39;] = links</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comments = list()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comment = dict()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comment[&#39;dateTime&#39;] = &quot;10:43 7/20/2004&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comment[&#39;author&#39;] = &quot;ygp&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comment[&#39;comment&#39;] = &quot;blah&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comments.append(comment)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; items = list()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for content in latest_content_list:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; item = dict()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; item[&#39;title&#39;] = content.subject<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; item[&#39;body&#39;] = content.content
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; item[&#39;author&#39;] = <a href="http://user.name">user.name</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; item[&#39;permalink&#39;] = &quot;perma link&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; item[&#39;time&#39;] = &quot;13234 23423423&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; item[&#39;comments&#39;] = comments<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; items.append(item)</p>
<p><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blog[&#39;items&#39;] = items</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileHandle = open ( &#39;/var/chroot/www/htdocs/django/js/model.js&#39;, &#39;w&#39; )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileHandle.write( codecs.BOM_UTF8 )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &gt;&gt; fileHandle, &#39;var blog = &#39;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &gt;&gt; fileHandle, blog
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileHandle.close()</p></blockquote>
<div>This is the part of my whole source code.</div>
<div>&nbsp;</div>
<div>I try to convert the python dict into javascript array.</div>
<div>&nbsp;</div>
<div>Because they have same syntax.</div>
<div>&nbsp;</div>
<div>So when I print out the the dict, this is valid javascript array.</div>
<div>&nbsp;</div>
<div>And then I parsed the javascript array to display html page. But when I print out the python dict.</div>
<div>&nbsp;</div>
<div>the __str__ function don&#39;t have any encode routine. so I guess this problem is caused.</div>
<div>&nbsp;</div>
<div>The below is my wonder.</div>
<div>&nbsp;</div>
<div>Do I need to make my own fuction which to convert the dict value to utf-8?</div>
<div>&nbsp;</div>
<div>Or Is there any other way to display dict&#39;s korean letter properly?</div>
<div><br><br>&nbsp;</div>
<div><span class="gmail_quote">On 5/31/07, <b class="gmail_sendername">Kent Johnson</b> &lt;<a href="mailto:kent37@tds.net">kent37@tds.net</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Young-gyu Park wrote:<br><br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileHandle = open (<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &#39;/var/chroot/www/htdocs/django/js/model.js&#39;, &#39;w&#39; )
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileHandle.write( codecs.BOM_UTF8 )<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &gt;&gt; fileHandle, &#39;var blog = &#39;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &gt;&gt; fileHandle, blog<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileHandle.close()<br>&gt;
<br>&gt;<br>&gt; this is the file model.js<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; var blog =<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;description&#39;: &#39;\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad<br>....<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<a href="http://www.hideout.com.br">http://www.hideout.com.br
</a>&gt;&#39;, &#39;title&#39;: &#39;\xed\x9b\x84\xec\x9b\x90&#39;}]}<br>&gt;<br>&gt;<br>&gt; What I want to do is to see properly the letter not this letter &#39;\xec\x9d&#39;<br>&gt;<br>&gt; Can anyone who know solution let me know how to do kindly?
<br><br>You haven&#39;t shown us enough code. Where does the variable blog come from?<br><br>This is a hard question to answer because there are so many ways to get<br>confused. How did you display the file? It is possible that it contains
<br>the correct characters but the method you are using to display them<br>shows them as \x escapes. For example the Python interpreter will do this.<br><br>It looks like you are using a JSON encoder to create the data. Which
<br>one? Here is an example using the version of SimpleJSON that is bundled<br>with Django. It does what you want but it&#39;s a little tricky to be sure:<br><br>In [3]: from django.utils.simplejson import dumps<br><br>This is Python so I can use \x escapes to define the string; the actual
<br>string is UTF-8:<br><br>In [4]: data = {&#39;description&#39;: &#39;\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad<br>\xed\x91\xb8\xeb\xa6\x84\xed\x84\xb0&#39;}<br><br>If I ask the interpreter for the value directly, it shows it with
<br>escapes. (Technically, the interpreter prints repr(value) for any value<br>it is asked to display; for strings, repr() inserts \x escapes so the<br>result is printable ASCII text.)<br><br>In [7]: data[&#39;description&#39;]
<br>Out[7]: &#39;\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad<br>\xed\x91\xb8\xeb\xa6\x84\xed\x84\xb0&#39;<br><br>On the other hand, if I ask the interpreter explicitly to print the<br>value, the \x escapes are not inserted and the correct characters are shown:
<br><br>In [8]: print data[&#39;description&#39;]<br>Ä«Å縯 Çª¸§ÅÍ<br><br>The parameter ensure_ascii=False prevents the JSON serializer from<br>converting the individual bytes of UTF-8 to \u escapes.<br><br>Here again, showing the converted data directly uses repr() and shows \x
<br>escapes:<br><br>In [6]: dumps(data, ensure_ascii=False)<br>Out[6]: &#39;{&quot;description&quot;: &quot;\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad<br><br>If I print the result, I can see that it contains the correct characters:
<br><br>In [17]: print dumps(data, ensure_ascii=False)<br>{&quot;description&quot;: &quot;Ä«Å縯 Çª¸§ÅÍ&quot;}<br><br>Kent<br></blockquote></div><br>