<div> </div>
<div> </div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<p> user = User.objects.get(userID__exact=user_id)<br> user.blog_set.all()<br> blogData = user.blog_set.get(id__exact=<a href="http://user.id">user.id</a>)<br> section_list = blogData.section_set.all
()<br> latest_content_list = blogData.content_set.all().order_by('-pub_date')[:5]</p>
<p> blog = dict()<br> blog['currentPost'] = {"dateIndex":0, "postIndex":0}</p>
<p> blog['title'] = blogData.name.encode('utf-8')<br> blog['description'] = blogData.description.encode('utf-8')</p>
<p> sections = list()<br> for section in section_list:<br> sections.append({"title":section.name.strip(), "link":"<a href="http://www.hideout.com.br/">www.hideout.com.br
</a>"})<br> blog['sections'] = sections</p>
<p> links = list()<br> link = dict()<br> links.append({"title":user_id, "link":"<a href="http://www.hideout.com.br/">www.hideout.com.br</a>"})<br> links.append({"title":"hideout", "link":"
<a href="http://www.hideout.com.br/">www.hideout.com.br</a>"})<br> links.append({"title":"hideout", "link":"<a href="http://www.hideout.com.br/">www.hideout.com.br</a>"})
<br> links.append({"title":"hideout", "link":"<a href="http://www.hideout.com.br/">www.hideout.com.br</a>"})</p>
<p> blog['links'] = links</p>
<p> comments = list()<br> comment = dict()<br> comment['dateTime'] = "10:43 7/20/2004"<br> comment['author'] = "ygp"<br> comment['comment'] = "blah"
<br> comments.append(comment)</p>
<p> items = list()<br> for content in latest_content_list:<br> item = dict()<br> item['title'] = content.subject<br> item['body'] = content.content
<br> item['author'] = <a href="http://user.name">user.name</a><br> item['permalink'] = "perma link"<br> item['time'] = "13234 23423423"
<br> item['comments'] = comments<br> items.append(item)</p>
<p><br> blog['items'] = items</p>
<p> fileHandle = open ( '/var/chroot/www/htdocs/django/js/model.js', 'w' )<br> fileHandle.write( codecs.BOM_UTF8 )<br> print >> fileHandle, 'var blog = '<br> print >> fileHandle, blog
<br> fileHandle.close()</p></blockquote>
<div>This is the part of my whole source code.</div>
<div> </div>
<div>I try to convert the python dict into javascript array.</div>
<div> </div>
<div>Because they have same syntax.</div>
<div> </div>
<div>So when I print out the the dict, this is valid javascript array.</div>
<div> </div>
<div>And then I parsed the javascript array to display html page. But when I print out the python dict.</div>
<div> </div>
<div>the __str__ function don't have any encode routine. so I guess this problem is caused.</div>
<div> </div>
<div>The below is my wonder.</div>
<div> </div>
<div>Do I need to make my own fuction which to convert the dict value to utf-8?</div>
<div> </div>
<div>Or Is there any other way to display dict's korean letter properly?</div>
<div><br><br> </div>
<div><span class="gmail_quote">On 5/31/07, <b class="gmail_sendername">Kent Johnson</b> <<a href="mailto:kent37@tds.net">kent37@tds.net</a>> 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>> fileHandle = open (<br>> '/var/chroot/www/htdocs/django/js/model.js', 'w' )
<br>> fileHandle.write( codecs.BOM_UTF8 )<br>> print >> fileHandle, 'var blog = '<br>> print >> fileHandle, blog<br>> fileHandle.close()<br>>
<br>><br>> this is the file model.js<br>><br>><br>> var blog =<br>> {'description': '\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad<br>....<br>> <<a href="http://www.hideout.com.br">http://www.hideout.com.br
</a>>', 'title': '\xed\x9b\x84\xec\x9b\x90'}]}<br>><br>><br>> What I want to do is to see properly the letter not this letter '\xec\x9d'<br>><br>> Can anyone who know solution let me know how to do kindly?
<br><br>You haven'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'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 = {'description': '\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad<br>\xed\x91\xb8\xeb\xa6\x84\xed\x84\xb0'}<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['description']
<br>Out[7]: '\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad<br>\xed\x91\xb8\xeb\xa6\x84\xed\x84\xb0'<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['description']<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]: '{"description": "\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>{"description": "Ä«Å縯 Ǫ¸§ÅÍ"}<br><br>Kent<br></blockquote></div><br>