Re: [Tutor] How can I see properly my korean.

2007-05-31 Thread Young-gyu Park

Yes, It works.

Thank you so much kent.

you make the time when I spent two days for solving this problem useless.

you are genious ^^

Why I didn't know that *"from django.utils.simplejson import dumps" !!!*

Do you have anything which you want to let me know, when I develop the ajax
application by Django?

Best regards.



On 5/31/07, Kent Johnson <[EMAIL PROTECTED]> wrote:


Young-gyu Park wrote:
> fileHandle = open (
> '/var/chroot/www/htdocs/django/js/model.js', 'w' )
> fileHandle.write( codecs.BOM_UTF8 )
> print >> fileHandle, 'var blog = '
> print >> fileHandle, blog
> fileHandle.close()
>
> This is the part of my whole source code.

OK, blog is a dict containing nested dicts. The problem is that printing
a dict prints the repr() of the contents of the dict, which gives you
the \x escapes for your strings.
>
> I try to convert the python dict into javascript array.

Since you are clearly using Django, I suggest you use the simplejson
module to do the serialization as I showed in my previous email. Instead
of
print >> fileHandle, blog
try
print >> fileHandle, dumps(blog, ensure_ascii=False)

where dumps is imported from django.utils.simplejson

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How can I see properly my korean.

2007-05-31 Thread Young-gyu Park

user = User.objects.get(userID__exact=user_id)
user.blog_set.all()
blogData = user.blog_set.get(id__exact=user.id)
section_list = blogData.section_set.all()
latest_content_list = blogData.content_set.all
().order_by('-pub_date')[:5]

blog = dict()
blog['currentPost'] = {"dateIndex":0, "postIndex":0}

blog['title'] = blogData.name.encode('utf-8')
blog['description'] = blogData.description.encode('utf-8')

sections = list()
for section in section_list:
sections.append({"title":section.name.strip(), "link":"
www.hideout.com.br"})
blog['sections'] = sections

links = list()
link = dict()
links.append({"title":user_id, "link":"www.hideout.com.br"})
links.append({"title":"hideout", "link":"www.hideout.com.br"})
links.append({"title":"hideout", "link":"www.hideout.com.br"})
links.append({"title":"hideout", "link":"www.hideout.com.br"})

blog['links'] = links

comments = list()
comment = dict()
comment['dateTime'] = "10:43 7/20/2004"
comment['author'] = "ygp"
comment['comment'] = "blah"
comments.append(comment)

items = list()
for content in latest_content_list:
item = dict()
item['title'] = content.subject
item['body'] = content.content
item['author'] = user.name
item['permalink'] = "perma link"
item['time'] = "13234 23423423"
item['comments'] = comments
items.append(item)


blog['items'] = items

fileHandle = open ( '/var/chroot/www/htdocs/django/js/model.js',
'w' )
fileHandle.write( codecs.BOM_UTF8 )
print >> fileHandle, 'var blog = '
print >> fileHandle, blog
fileHandle.close()


This is the part of my whole source code.

I try to convert the python dict into javascript array.

Because they have same syntax.

So when I print out the the dict, this is valid javascript array.

And then I parsed the javascript array to display html page. But when I
print out the python dict.

the __str__ function don't have any encode routine. so I guess this problem
is caused.

The below is my wonder.

Do I need to make my own fuction which to convert the dict value to utf-8?

Or Is there any other way to display dict's korean letter properly?



On 5/31/07, Kent Johnson <[EMAIL PROTECTED]> wrote:


Young-gyu Park wrote:

> fileHandle = open (
> '/var/chroot/www/htdocs/django/js/model.js', 'w' )
> fileHandle.write( codecs.BOM_UTF8 )
> print >> fileHandle, 'var blog = '
> print >> fileHandle, blog
> fileHandle.close()
>
>
> this is the file model.js
>
>
> var blog =
> {'description': '\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad

> <http://www.hideout.com.br>', 'title': '\xed\x9b\x84\xec\x9b\x90'}]}
>
>
> What I want to do is to see properly the letter not this letter
'\xec\x9d'
>
> Can anyone who know solution let me know how to do kindly?

You haven't shown us enough code. Where does the variable blog come from?

This is a hard question to answer because there are so many ways to get
confused. How did you display the file? It is possible that it contains
the correct characters but the method you are using to display them
shows them as \x escapes. For example the Python interpreter will do this.

It looks like you are using a JSON encoder to create the data. Which
one? Here is an example using the version of SimpleJSON that is bundled
with Django. It does what you want but it's a little tricky to be sure:

In [3]: from django.utils.simplejson import dumps

This is Python so I can use \x escapes to define the string; the actual
string is UTF-8:

In [4]: data = {'description': '\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad
\xed\x91\xb8\xeb\xa6\x84\xed\x84\xb0'}

If I ask the interpreter for the value directly, it shows it with
escapes. (Technically, the interpreter prints repr(value) for any value
it is asked to display; for strings, repr() inserts \x escapes so the
result is printable ASCII text.)

In [7]: data['description']
Out[7]: '\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad
\xed\

Re: [Tutor] How can I see properly my korean.

2007-05-31 Thread Young-gyu Park

Yes I did

I added the locale code at the top of my python code.

What I want to do is that I want to convert to python dict to javascript
associative array.

and I will get the javascript array to display in the html page.

But the korean letter which is in the python dict is displayed raw format (
I can't find any appropriate expression ) such as \x0e\xed\xff

I want to see the korean letters like 라재 라재

how I convert the python dict to javascript array?


On 5/31/07, Alan Gauld <[EMAIL PROTECTED]> wrote:


>I input the data which is from the database into array.
> and then I print out the array to the file
> but the letter I can not figure out.
>
>> fileHandle = open (
>> '/var/chroot/www/htdocs/django/js/model.js',
>> 'w' )
>> fileHandle.write( codecs.BOM_UTF8 )
>> print >> fileHandle, 'var blog = '
>> print >> fileHandle, blog
>> fileHandle.close()
>
>
> What I want to do is to see properly the letter not this letter
> '\xec\x9d'
>
> Can anyone who know solution let me know how to do kindly?

I think you need to set the locale at the top of your python code.
I have no idea what you need to do in your JavaScript however.

Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How can I see properly my korean.

2007-05-30 Thread Young-gyu Park

I input the data which is from the database into array.

and then I print out the array to the file

but the letter I can not figure out.




fileHandle = open ( '/var/chroot/www/htdocs/django/js/model.js',
'w' )
fileHandle.write( codecs.BOM_UTF8 )
print >> fileHandle, 'var blog = '
print >> fileHandle, blog
fileHandle.close()



this is the file model.js



var blog =
{'description': '\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad
\xed\x91\xb8\xeb\xa6\x84\xed\x84\xb0', 'links': [{'link': '
www.hideout.com.br', 'title': 'ggum'}, {'link': 'www.hideout.com.br',
'title': 'hideout'}, {'link': 'www.hideout.com.br', 'title': 'hideout'},
{'link': 'www.hideout.com.br', 'title': 'hideout'}], 'title':
u'\uce74\ud1a8\ub9ad \ud478\ub984\ud130', 'items': [{'body':
'\xeb\xaf\xbc\xec\x95\x84\xeb\x9e\x80\xe3\x85\x81\xec\x95\x8c\r\n\r\n\xed\x85\x8c\xec\x8a\xa4\xed\x8a\xb8\xec\x9e\x85\xeb\x8b\x88\xe3\x85\x8f.',
'permalink': 'perma link', 'author': 'ggum', 'title':
'\xec\xb2\xab\xeb\xb2\x88 \xec\xa7\xb8
\xea\xb3\xb5\xec\xa7\x80\xec\x82\xac\xed\x95\xad', 'comments': [{'comment':
'blah', 'author': 'ygp', 'dateTime': '10:43 7/20/2004'}], 'time': '13234
23423423'}, {'body': '\xec\x98\xa4\xeb\x8a\x98\xec\x9d\x80
\xec\xa0\x95\xeb\xa7\x90
\xec\x9e\xac\xeb\xb0\x8c\xec\x97\x88\xeb\x8b\xa4.\r\n\r\n\xeb\x98\x90
\xed\x95\x9c\xeb\xb2\x88 \xeb\x8d\x94...', 'permalink': 'perma link',
'author': 'ggum', 'title': '\xec\x98\xa4\xeb\x8a\x98\xec\x9d\x98
\xec\x9d\xb4\xec\x95\xbc\xea\xb8\xb0', 'comments': [{'comment': 'blah',
'author': 'ygp', 'dateTime': '10:43 7/20/2004'}], 'time': '13234
23423423'}], 'currentPost': {'dateIndex': 0, 'postIndex': 0}, 'sections':
[{'link': 'www.hideout.com.br', 'title':
'\xea\xb3\xb5\xec\xa7\x80\xec\x82\xac\xed\x95\xad'}, {'link': '
www.hideout.com.br', 'title':
'\xec\x9a\xb0\xeb\xa6\xac\xeb\x93\xa4\xec\x9d\x98
\xec\x9d\xb4\xec\x95\xbc\xea\xb8\xb0'}, {'link': 'www.hideout.com.br',
'title': '\xed\x9b\x84\xec\x9b\x90'}]}



What I want to do is to see properly the letter not this letter '\xec\x9d'

Can anyone who know solution let me know how to do kindly?

Thanks a lot.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor