[Tutor] How can I see properly my korean.

2007-05-31 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


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

2007-05-31 Thread Alan Gauld
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


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


Re: [Tutor] leave tutorial

2007-05-31 Thread Kent Johnson
Kriti Satija wrote:
 i want to leave the tutorial 

If you mean you want to unsubscribe to the tutor list, click the link at 
the bottom of each posting and you will get to a form that lets you 
unsubscribe.

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 Kent Johnson
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\x91\xb8\xeb\xa6\x84\xed\x84\xb0'

On the other hand, if I ask the interpreter explicitly to print the 
value, the \x escapes are not inserted and the correct characters are shown:

In [8]: print data['description']
카톨릭 푸름터

The parameter ensure_ascii=False prevents the JSON serializer from 
converting the individual bytes of UTF-8 to \u escapes.

Here again, showing the converted data directly uses repr() and shows \x 
escapes:

In [6]: dumps(data, ensure_ascii=False)
Out[6]: '{description: \xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad

If I print the result, I can see that it contains the correct characters:

In [17]: print dumps(data, ensure_ascii=False)
{description: 카톨릭 푸름터}

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 Kent Johnson
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] creating a buffer object from a file ?

2007-05-31 Thread Iyer
I think this got lost among the threads:


in reality what is a buffer object used for ? reading
a file itself creates a string as in itself, 

file_handle = file (path_to_file)

file_data = file_handle.read()

# file_data is a string, so why is a buffer object is
needed ?

the data in the binary file is just raw binary. 

I apologize for replying to the existing subject.
Thanks for letting me know. I shall make sure this
doesn't happen again.

thanks
iyer

--- Alan Gauld [EMAIL PROTECTED] wrote:

 Iyer [EMAIL PROTECTED] wrote
 
  How do I go about creating a buffer object from
  a file containing binary data ? I have a function
  that accepts only buffer objects for it's
 parameters
 
 Can you define what you mean by a buffer object?
 Python uses duck typing so, unless the function has
 been badly coded with an explicit type check, it
 should accept any object that supports the methods
 used.
 
 If you really do need a buffer the docs say:
 
 -
 Buffer objects are not directly supported by Python
 syntax, but can be created by calling the builtin
 function buffer(). They don't support concatenation
 or repetition.
 -
 
 Which was new to me. But some experimentation
 with the interpreter shows:
 
 class buffer(object)
  |  buffer(object [, offset[, size]])
  |
  |  Create a new buffer object which references the
 given object.
  |  The buffer will reference a slice of the target
 object from the
  |  start of the object (or at the specified
 offset). The slice will
  |  extend to the end of the target object (or with
 the specified 
 size).
 ---
 and
 
  b = buffer('fredrica', 2,4)
  b[:]
 'edri'
 
 
 So we can see how to create a buffer object.
 You want to do it with a binary file. You can read
 the content
 of a binary file using the struct module. But you
 need to know
 what kind of data is in your file. To create a
 buffer you need
 a string. So do you want your buffer to process the
 raw binary
 bytes as if they were a string? Or do you want to
 convert the
 binary data and then convert it again into a string
 representation?
 
 Either is possible but you need to decide which you
 need.
 
 BTW Please don't post new subjects to the list by
 replying
 to an existing subject. For those using threaded
 readers it
 buries your post insife another thread, in this case
 3 levels
 deep in one about MSSQL! I only just noticed it. Its
 better
 to start a fresh message. After all its not exactly 
 difficult to
 type tutor@python.org in the to line! :-)
 
 HTH,
 
 -- 
 Alan Gauld
 Author of the Learn to Program web site
 http://www.freenetpages.co.uk/hp/alan.gauld
 
 
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 


 

No need to miss a message. Get email on-the-go 
with Yahoo! Mail for Mobile. Get started.
http://mobile.yahoo.com/mail 
___
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

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 Kent Johnson
Young-gyu Park wrote:

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

Well, it's off topic for this list, and I don't really want to be a 
JavaScript / AJAX tutor, but I will say that it is easy to serve JSON 
directly from a Django view and using jQuery on the client side makes it 
easy to fetch the data with XmlHttpRequest.

Here are some starting points:
http://wolfram.kriesing.de/blog/index.php/2007/json-serialization-for-django
http://www.djangosnippets.org/snippets/154/
http://docs.jquery.com/Ajax#.24.getJSON.28_url.2C_params.2C_callback_.29

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


[Tutor] configparser -- suggestions on when name: value entries are incomplete

2007-05-31 Thread Iyer
Regarding the configparser module, if there is a
configuration file to be read that has incomplete
name: value entries, what would be the best way to
handle this situation ?

I was thinking of catching the exemption parsingerror
and deleting the sections that have incomplete
name:value entries, to delete the sections, the
configfile has to be read, right and that raises the
parsing error.

any suggestions on how to best handle this situation?

iyer


   

Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, 
photos  more. 
http://mobile.yahoo.com/go?refer=1GNXIC
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a buffer object from a file ?

2007-05-31 Thread Jerry Hill
On 5/31/07, Iyer [EMAIL PROTECTED] wrote:
 I think this got lost among the threads:

I think it got lost because you haven't given us enough information to
answer your question.

 in reality what is a buffer object used for ? reading
 a file itself creates a string as in itself,

We don't know.  Your original email said you needed a buffer object,
but didn't tell us why.  As a consequence, the only one who knows why
you need one is you.  Perhaps if you actually showed us some code, or
mentioned what library you were using that required a buffer object?

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


Re: [Tutor] configparser -- suggestions on when name: value entries are incomplete

2007-05-31 Thread Kent Johnson
Iyer wrote:
 Regarding the configparser module, if there is a
 configuration file to be read that has incomplete
 name: value entries, what would be the best way to
 handle this situation ?

Do you mean incomplete as in not syntactically correct? I would tell the 
user to fix it.

If you mean missing some values, you could provide defaults.

 
 I was thinking of catching the exemption parsingerror
 and deleting the sections that have incomplete
 name:value entries, to delete the sections, the
 configfile has to be read, right and that raises the
 parsing error.
 
 any suggestions on how to best handle this situation?

Don't accept garbage data.

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


Re: [Tutor] configparser -- suggestions on when name: value entries are incomplete

2007-05-31 Thread Iyer

--- Kent Johnson [EMAIL PROTECTED] wrote:

 Iyer wrote:
  Regarding the configparser module, if there is a
  configuration file to be read that has incomplete
  name: value entries, what would be the best way
 to
  handle this situation ?
 
 Do you mean incomplete as in not syntactically
 correct? I would tell the 
 user to fix it.

yes, it is not syntactically correct - for one section
there are no corresponding names for the values; the
values show up in the config file. This config file is
actually generated by another program not under my
control and breaks my python script trying to read it.
 

 
 If you mean missing some values, you could provide
 defaults.
 
  
  I was thinking of catching the exemption
 parsingerror
  and deleting the sections that have incomplete
  name:value entries, to delete the sections, the
  configfile has to be read, right and that raises
 the
  parsing error.
  
  any suggestions on how to best handle this
 situation?
 
 Don't accept garbage data.
 
 Kent
 



   

Pinpoint customers who are looking for what you sell. 
http://searchmarketing.yahoo.com/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a buffer object from a file ?

2007-05-31 Thread Alan Gauld

Jerry Hill [EMAIL PROTECTED] wrote

 I think this got lost among the threads:

 I think it got lost because you haven't given us enough information 
 to
 answer your question.

 in reality what is a buffer object used for ? reading
 a file itself creates a string as in itself,

 We don't know.  Your original email said you needed a buffer object,

The problem is that the Python docs refer to a buffer object
but are not very forthcoming about exactly what it is or when/why
you should use one. I confess that until Iyer asked his question
I didn't even know they existed and still don't know when or
why I'd need one.

They appear to be some kind of string based object used in
the internals of Python but with some operations blocked.
But the only halfway useful info is what you get when you
do help(buffer).

Sorry Iyer, I can't really tell you anymore than I did already.

As Jerry says, maybe if  you could remind us of the context
where you were told you needed to use a buffer object? I've never
seen such a demand in Python myself.

Alan G. 


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


Re: [Tutor] (no subject)

2007-05-31 Thread Rikard Bosnjakovic
On 5/30/07, Treloar, Nick [EMAIL PROTECTED] wrote:

 how do you import sounds

Do you mean a module named sounds, or sounds in general? If the
latter, what do you mean by import sounds? Read a sound-file? Play a
sound-file?

There is a wav-module you can use: http://docs.python.org/lib/module-wave.html

If you want to play sounds, check pygame: http://www.pygame.org/


-- 
- Rikard - http://bos.hack.org/cv/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor