Re: [Tutor] encoding question

2014-01-05 Thread eryksun
On Sun, Jan 5, 2014 at 5:26 PM, Steven D'Aprano wrote: > On Sun, Jan 05, 2014 at 11:02:34AM -0500, eryksun wrote: >> >> > > That surprises me. I thought XML was only valid in UTF-8? Or maybe that > was wishful thinking. JSON text SHALL be encoded in Unicode: https://tools.ietf.org/html/rfc4

Re: [Tutor] encoding question

2014-01-05 Thread Alex Kleider
On 2014-01-05 14:26, Steven D'Aprano wrote: On Sun, Jan 05, 2014 at 11:02:34AM -0500, eryksun wrote: Danny walked you through the XML. Note that he didn't decode the response. It includes an encoding on the first line: That surprises me. I thought XML was only valid in UTF-8? Or maybe t

Re: [Tutor] encoding question

2014-01-05 Thread Steven D'Aprano
On Sun, Jan 05, 2014 at 11:02:34AM -0500, eryksun wrote: > Danny walked you through the XML. Note that he didn't decode the > response. It includes an encoding on the first line: > > That surprises me. I thought XML was only valid in UTF-8? Or maybe that was wishful thinking. > tr

Re: [Tutor] encoding question

2014-01-05 Thread Alex Kleider
On 2014-01-05 08:02, eryksun wrote: On Sun, Jan 5, 2014 at 2:57 AM, Alex Kleider wrote: def ip_info(ip_address): response = urllib2.urlopen(url_format_str %\ (ip_address, )) encoding = response.headers.getparam('charset') print "'encoding' is '%s

Re: [Tutor] encoding question

2014-01-05 Thread eryksun
On Sun, Jan 5, 2014 at 2:57 AM, Alex Kleider wrote: > def ip_info(ip_address): > > response = urllib2.urlopen(url_format_str %\ >(ip_address, )) > encoding = response.headers.getparam('charset') > print "'encoding' is '%s'." % (encoding, ) > inf

Re: [Tutor] encoding question

2014-01-05 Thread Steven D'Aprano
On Sat, Jan 04, 2014 at 11:57:20PM -0800, Alex Kleider wrote: > Well, I've tried the xml approach which seems promising but still I get > an encoding related error. > Is there a bug in the xml.etree module (not very likely, me thinks) or > am I doing something wrong? I'm no expert on XML, but i

Re: [Tutor] encoding question

2014-01-05 Thread Mark Lawrence
On 05/01/2014 02:31, Alex Kleider wrote: I've been maintaining both a Python3 and a Python2.7 version. The latter has actually opened my eyes to more complexities. Specifically the need to use unicode strings rather than Python2.7's default ascii. This might help http://python-future.org/ -

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/05/2014 08:57 AM, Alex Kleider wrote: On 2014-01-04 21:20, Danny Yoo wrote: Oh! That's unfortunate! That looks like a bug on the hostip.info side. Check with them about it. I can't get the source code to whatever is implementing the JSON response, so I can not say why the city is not

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/05/2014 03:31 AM, Alex Kleider wrote: I've been maintaining both a Python3 and a Python2.7 version. The latter has actually opened my eyes to more complexities. Specifically the need to use unicode strings rather than Python2.7's default ascii. So-called Unicode strings are not the solut

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/04/2014 08:26 PM, Alex Kleider wrote: Any suggestions as to a better way to handle the problem of encoding in the following context would be appreciated. The problem arose because 'Bogota' is spelt with an acute accent on the 'a'. $ cat IP_info.py3 #!/usr/bin/env python3 # -*- coding : ut

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/05/2014 12:52 AM, Steven D'Aprano wrote: If you don't understand an exception, you have no business covering it up and hiding that it took place. Never use a bare try...except, always catch the *smallest* number of specific exception types that make sense. Better is to avoid catching except

Re: [Tutor] encoding question

2014-01-04 Thread Alex Kleider
On 2014-01-04 21:20, Danny Yoo wrote: Oh! That's unfortunate! That looks like a bug on the hostip.info side. Check with them about it. I can't get the source code to whatever is implementing the JSON response, so I can not say why the city is not being properly included there. [... XML ran

Re: [Tutor] encoding question

2014-01-04 Thread Alex Kleider
On 2014-01-04 21:20, Danny Yoo wrote: Oh! That's unfortunate! That looks like a bug on the hostip.info side. Check with them about it. I can't get the source code to whatever is implementing the JSON response, so I can not say why the city is not being properly included there. [... XML ran

Re: [Tutor] encoding question

2014-01-04 Thread Danny Yoo
> then? I'm convinced that all the extraneous structure and complexity > in XML causes the people who work with it to stop caring, the result > being something that isn't for the benefit of either humans nor > computer programs. ... I'm sorry. Sometimes I get grumpy when I haven't had a Snicker

Re: [Tutor] encoding question

2014-01-04 Thread Danny Yoo
Oh! That's unfortunate! That looks like a bug on the hostip.info side. Check with them about it. I can't get the source code to whatever is implementing the JSON response, so I can not say why the city is not being properly included there. [... XML rant about to start. I am not disintereste

Re: [Tutor] encoding question

2014-01-04 Thread eryksun
On Sat, Jan 4, 2014 at 11:16 PM, Alex Kleider wrote: > {u'city': None, u'ip': u'201.234.178.62', u'lat': u'10.4', u'country_code': > u'CO', u'country_name': u'COLOMBIA', u'lng': u'-75.2833'} > > If I use my own IP the city comes in fine so there must still be some > problem with the encoding. Rep

Re: [Tutor] encoding question

2014-01-04 Thread Alex Kleider
On 2014-01-04 18:44, Danny Yoo wrote: Hi Alex, According to: http://www.hostip.info/use.html there is a JSON-based interface. I'd recommend using that one! JSON is a format that's easy for machines to decode. The format you're parsing is primarily for humans, and who knows if that will

Re: [Tutor] encoding question

2014-01-04 Thread Dave Angel
On Sat, 04 Jan 2014 18:31:13 -0800, Alex Kleider wrote: exactly what the line # -*- coding : utf -8 -*- really indicates or more importantly, is it true, since I am using vim and I assume things are encoded as ascii? I don't know vim specifically, but I'm 99% sure it will let you specify

Re: [Tutor] encoding question

2014-01-04 Thread Danny Yoo
You were asking earlier about the line: # -*- coding : utf -8 -*- See PEP 263: http://www.python.org/dev/peps/pep-0263/ http://docs.python.org/release/2.3/whatsnew/section-encodings.html It's a line that tells Python how to interpret the bytes of your source program. It allows us t

Re: [Tutor] encoding question

2014-01-04 Thread Danny Yoo
Hi Alex, According to: http://www.hostip.info/use.html there is a JSON-based interface. I'd recommend using that one! JSON is a format that's easy for machines to decode. The format you're parsing is primarily for humans, and who knows if that will change in the future to make it easier

Re: [Tutor] encoding question

2014-01-04 Thread Alex Kleider
A heartfelt thank you to those of you that have given me much to ponder with your helpful responses. In the mean time I've rewritten my procedure using a different approach all together. I'd be interested in knowing if you think it's worth keeping or do you suggest I use your revisions to my or

Re: [Tutor] encoding question

2014-01-04 Thread Steven D'Aprano
On Sat, Jan 04, 2014 at 04:15:30PM -0800, Alex Kleider wrote: > >py> 'Bogotá'.encode('utf-8') > > I'm interested in knowing how you were able to enter the above line > (assuming you have a key board similar to mine.) I'm running Linux, and I use the KDE or Gnome character selector, depending o

Re: [Tutor] encoding question

2014-01-04 Thread Steven D'Aprano
Following my previous email... On Sat, Jan 04, 2014 at 11:26:35AM -0800, Alex Kleider wrote: > Any suggestions as to a better way to handle the problem of encoding in > the following context would be appreciated. The problem arose because > 'Bogota' is spelt with an acute accent on the 'a'. Er

Re: [Tutor] encoding question

2014-01-04 Thread eryksun
On Sat, Jan 4, 2014 at 7:15 PM, Alex Kleider wrote: >> >> py> 'Bogotá'.encode('utf-8') > > I'm interested in knowing how you were able to enter the above line > (assuming you have a key board similar to mine.) I use an international keyboard layout: https://en.wikipedia.org/wiki/QWERTY#US-Intern

Re: [Tutor] encoding question

2014-01-04 Thread Alex Kleider
On 2014-01-04 15:52, Steven D'Aprano wrote: Oh great. An exception was raised. What sort of exception? What error message did it have? Why did it happen? Nobody knows, because you throw it away. Never, never, never do this. If you don't understand an exception, you have no business covering it

Re: [Tutor] encoding question

2014-01-04 Thread Steven D'Aprano
On Sat, Jan 04, 2014 at 11:26:35AM -0800, Alex Kleider wrote: > Any suggestions as to a better way to handle the problem of encoding in > the following context would be appreciated. Python gives you lots of useful information when errors occur, but unfortunately your code throws that information

Re: [Tutor] encoding question

2014-01-04 Thread Alex Kleider
On 2014-01-04 12:01, eryksun wrote: On Sat, Jan 4, 2014 at 2:26 PM, Alex Kleider wrote: . b'\xe1' is Latin-1. Look in the response headers: url = 'http://api.hostip.info/get_html.php?ip=201.234.178.62&position=true' >>> response = urllib.request.urlopen(url) >>> response.h

Re: [Tutor] encoding question

2014-01-04 Thread eryksun
On Sat, Jan 4, 2014 at 2:26 PM, Alex Kleider wrote: > The output I get on an Ubuntu 12.4LTS system is as follows: > alex@x301:~/Python/Parse$ ./IP_info.py3 > Exception raised. > IP address is 201.234.178.62: > Country: COLOMBIA (CO); City: b'Bogot\xe1'. > Lat/Long: 10.4/-75.28

Re: [Tutor] Encoding error when reading text files in Python 3

2012-07-28 Thread Dat Huynh
I change my code and it runs on Python 3 now. f = open(rootdir+file, 'rb') data = f.read().decode('utf8', 'ignore') Thank you very much. Sincerely, Dat. On Sat, Jul 28, 2012 at 6:09 PM, Steven D'Aprano wrote: > Dat Huynh wrote: >> >> Dear all, >> >> I have written a simp

Re: [Tutor] Encoding error when reading text files in Python 3

2012-07-28 Thread Steven D'Aprano
Dat Huynh wrote: Dear all, I have written a simple application by Python to read data from text files. Current I have both Python version 2.7.2 and Python 3.2.3 on my laptop. I don't know why it does not run on Python version 3 while it runs well on Python 2. Python 2 is more forgiving of beg

Re: [Tutor] Encoding

2011-11-18 Thread Prasad, Ramit
On 11/17/2011 8:45 PM, Nidian Job-Smith wrote: Hi all, In my programme I am encoding what the user has in-putted.  What the user inputs will in a string, which might a mixture of letters and numbers. However I only want the letters to be encoded. 

Re: [Tutor] Encoding

2011-11-18 Thread Max S.
Well, I am assuming that by this you mean converting user input into a string, and then extracting the numerals (0-9) from it. Next time, please tell us your version of Python. I'll do my best to help with this. You might try the following: the_input = input("Insert string here: ") # change to

Re: [Tutor] Encoding

2011-11-17 Thread bob gailer
On 11/17/2011 8:45 PM, Nidian Job-Smith wrote: Hi all, In my programme I am encoding what the user has in-putted. What the user inputs will in a string, which might a mixture of letters and numbers. However I only want the letters to be encoded. Does any-one how I can only allow the chara

Re: [Tutor] Encoding

2010-03-10 Thread Giorgio
2010/3/8 Dave Angel > >> You still didn't provide the full context. Are you trying to do store > binary data, or not? > Yes i think ti's binary data. I'm just reading with file.read a JPG image. Stefan: yes, read that tutorial :) Giorgio > > > -- -- AnotherNetFellow Email: anothernetfel.

Re: [Tutor] Encoding

2010-03-07 Thread Stefan Behnel
Giorgio, 05.03.2010 14:56: What i don't understand is why: s = u"ciao è ciao" is converting a string to unicode, decoding it from the specified encoding but t = "ciao è ciao" t = unicode(t) That should do exactly the same instead of using the specified encoding always assume that if i'm not te

Re: [Tutor] Encoding

2010-03-07 Thread Dave Angel
Giorgio wrote: 2010/3/7 Dave Angel Those two lines don't make any sense by themselves. Show us some context, and we can more sensibly comment on them. And try not to use names that hide built-in keywords, or Python stdlib names. Hi Dave, I'm considering Amazon SimpleDB as an alte

Re: [Tutor] Encoding

2010-03-07 Thread Giorgio
2010/3/7 Dave Angel > > Those two lines don't make any sense by themselves. Show us some context, > and we can more sensibly comment on them. And try not to use names that > hide built-in keywords, or Python stdlib names. > Hi Dave, I'm considering Amazon SimpleDB as an alternative to PGSQL,

Re: [Tutor] Encoding

2010-03-07 Thread Dave Angel
Giorgio wrote: 2010/3/7 spir One more question: Amazon SimpleDB only accepts UTF8. So, let's say i have to put into an image file: Do you mean a binary file with image data, such as a jpeg? In that case, an emphatic - NO. not even close. filestream = file.read() filetoput = filestr

Re: [Tutor] Encoding

2010-03-07 Thread python
ding, I'm puzzled why anyone would use the regular open() for anything but binary operations. Malcolm - Original message - From: "spir" To: "Python tutor" Date: Sun, 7 Mar 2010 14:29:11 +0100 Subject: Re: [Tutor] Encoding On Sun, 7 Mar 2010 13:23:12 +0100 Gi

Re: [Tutor] Encoding

2010-03-07 Thread spir
On Sun, 7 Mar 2010 13:23:12 +0100 Giorgio wrote: > One more question: Amazon SimpleDB only accepts UTF8. [...] > filestream = file.read() > filetoput = filestream.encode('utf-8') No! What is the content of the file? Do you think it can be a pure python representation of a unicode text? uConten

Re: [Tutor] Encoding

2010-03-07 Thread Giorgio
2010/3/7 spir > > > Oh, right. And, if i'm not wrong B is an UTF8 string decoded to unicode > (due > > to the coding: statement at the top of the file) and re-encoded to latin1 > > Si! :-) > Ahah. Ok, Grazie! One more question: Amazon SimpleDB only accepts UTF8. So, let's say i have to put int

Re: [Tutor] Encoding

2010-03-06 Thread Giorgio
2010/3/5 Dave Angel I'm not angry, and I'm sorry if I seemed angry. Tone of voice is hard to > convey in a text message. Ok, sorry. I've misunderstood your mail :D > I'm still not sure whether your confusion is to what the rules are, or why > the rules were made that way. WHY the rules are

Re: [Tutor] Encoding

2010-03-05 Thread Mark Tolonen
"Giorgio" wrote in message news:23ce85921003050915p1a084c0co73d973282d8fb...@mail.gmail.com... 2010/3/5 Dave Angel I think the problem is that i can't find any difference between 2 lines quoted above: a = u"ciao è ciao" and a = "ciao è ciao" a = unicode(a) Maybe this will help: # co

Re: [Tutor] Encoding

2010-03-05 Thread Dave Angel
Giorgio wrote: 2010/3/5 Dave Angel In other words, you don't understand my paragraph above. Maybe. But please don't be angry. I'm here to learn, and as i've run into a very difficult concept I want to fully undestand it. I'm not angry, and I'm sorry if I seemed angry. Tone of v

Re: [Tutor] Encoding

2010-03-05 Thread Giorgio
2010/3/5 Dave Angel > > In other words, you don't understand my paragraph above. Maybe. But please don't be angry. I'm here to learn, and as i've run into a very difficult concept I want to fully undestand it. > Once the string is stored in t as an 8 bit string, it's irrelevant what the > sour

Re: [Tutor] Encoding

2010-03-05 Thread Dave Angel
Giorgio wrote: Ok,so you confirm that: s = u"ciao è ciao" will use the file specified encoding, and that t = "ciao è ciao" t = unicode(t) Will use, if not specified in the function, ASCII. It will ignore the encoding I specified on the top of the file. right? A literal "u" str

Re: [Tutor] Encoding

2010-03-05 Thread Giorgio
> > >> Ok,so you confirm that: >> >> s = u"ciao è ciao" will use the file specified encoding, and that >> >> t = "ciao è ciao" >> t = unicode(t) >> >> Will use, if not specified in the function, ASCII. It will ignore the >> encoding I specified on the top of the file. right? >> >> >> > A literal "

Re: [Tutor] Encoding

2010-03-04 Thread Dave Angel
Giorgio wrote: 2010/3/4 spir Ok,so you confirm that: s = u"ciao è ciao" will use the file specified encoding, and that t = "ciao è ciao" t = unicode(t) Will use, if not specified in the function, ASCII. It will ignore the encoding I specified on the top of the file. right? A literal

Re: [Tutor] Encoding

2010-03-04 Thread Giorgio
2010/3/4 spir > > > How do you know your win XP terminal is configured to deal with text using > utf8? Why do you think it should? > I think there is an option in IDLE configuration to set this. So, if my entire system is not utf8 i can't use the IDLE for this test? > > This trial uses the def

Re: [Tutor] Encoding

2010-03-04 Thread spir
On Thu, 4 Mar 2010 15:13:44 +0100 Giorgio wrote: > Thankyou. > > You have clarificated many things in those emails. Due to high numbers of > messages i won't quote everything. > > So, as i can clearly understand reading last spir's post, python gets > strings encoded by my editor and to convert

Re: [Tutor] Encoding

2010-03-04 Thread Giorgio
Thankyou. You have clarificated many things in those emails. Due to high numbers of messages i won't quote everything. So, as i can clearly understand reading last spir's post, python gets strings encoded by my editor and to convert them to unicode i need to specify HOW they're encoded. This make

Re: [Tutor] Encoding

2010-03-04 Thread Albert-Jan Roskam
guess. ~~ --- On Thu, 3/4/10, spir wrote: From: spir Subject: Re: [Tutor] Encoding To: tutor@python.org Date: Thursday, March 4, 2010, 8:01 AM On Wed, 3 Mar 2010 20:44:51 +0100 Giorgio wrote: > Please let me post the third update O_o.

Re: [Tutor] Encoding

2010-03-03 Thread spir
On Wed, 3 Mar 2010 20:44:51 +0100 Giorgio wrote: > Please let me post the third update O_o. You can forgot other 2, i'll put > them into this email. > > --- > >>> s = "ciao è ciao" > >>> print s > ciao è ciao > >>> s.encode('utf-8') > > Traceback (most recent call last): > File "", line 1, in

Re: [Tutor] Encoding

2010-03-03 Thread python
Denis, That was a great explanation!! I'm not the OP, but your explanation really clicked with me. Regards, Malcolm For sure, but it's true for any kind of data, not only text :-) Think at music or images *formats*. The issue is a bit obscured for text but the use of the mysterious, _cryptic_ (

Re: [Tutor] Encoding

2010-03-03 Thread spir
On Wed, 3 Mar 2010 16:32:01 +0100 Giorgio wrote: > Uff, encoding is a very painful thing in programming. For sure, but it's true for any kind of data, not only text :-) Think at music or images *formats*. The issue is a bit obscured for text but the use of the mysterious, _cryptic_ (!), word "

Re: [Tutor] Encoding

2010-03-03 Thread Sander Sweers
On 3 March 2010 22:41, Sander Sweers wrote: > It is confusing but once understand how it works it makes sense. I remembered Kent explained it very clear in [1]. Greets Sander [1] http://mail.python.org/pipermail/tutor/2009-May/068920.html ___ Tutor ma

Re: [Tutor] Encoding

2010-03-03 Thread Sander Sweers
On 3 March 2010 20:44, Giorgio wrote: s = "ciao è ciao" print s > ciao è ciao s.encode('utf-8') > Traceback (most recent call last): >   File "", line 1, in >     s.encode('utf-8') > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 5: > ordinal not in range(128)

Re: [Tutor] Encoding

2010-03-03 Thread Dave Angel
(Don't top-post. Put your response below whatever you're responding to, or at the bottom.) Giorgio wrote: Ok. So, how do you encode .py files? UTF-8? 2010/3/3 Dave Angel I personally use Komodo to edit my python source files, and tell it to use UTF8 encoding. Then I add a encoding lin

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
I'm sorry, it's utf8_unicode_ci that's confusing me. So, "UTF-8 is one of the most commonly used encodings. UTF stands for "Unicode Transformation Format"" UTF8 is, we can say, a type of "unicode", right? And what about utf8_unicode_ci in mysql? Giorgio 2010/3/3 Stefan Behnel > Giorgio, 03.03.

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
Please let me post the third update O_o. You can forgot other 2, i'll put them into this email. --- >>> s = "ciao è ciao" >>> print s ciao è ciao >>> s.encode('utf-8') Traceback (most recent call last): File "", line 1, in s.encode('utf-8') UnicodeDecodeError: 'ascii' codec can't decode by

Re: [Tutor] Encoding

2010-03-03 Thread Stefan Behnel
Giorgio, 03.03.2010 18:28: string = u"blabla" This is unicode, ok. Unicode UTF-8? No, not UTF-8. Unicode. You may want to read this: http://www.amk.ca/python/howto/unicode Stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change su

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
Ops, i have another update: string = u"blabla" This is unicode, ok. Unicode UTF-8? Thankyou 2010/3/3 Giorgio > Ok. > > So, how do you encode .py files? UTF-8? > > 2010/3/3 Dave Angel > > Giorgio wrote: >> >>> > Depends on your python version. If you use python 2.x, you have to use

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
Ok. So, how do you encode .py files? UTF-8? 2010/3/3 Dave Angel > Giorgio wrote: > >> >>> Depends on your python version. If you use python 2.x, you have to use a >>> u before the string: >>> >>> s = u'Hallo World' >>> >>> >> >> >> Ok. So, let's go back to my first question

Re: [Tutor] Encoding

2010-03-03 Thread Dave Angel
Giorgio wrote: Depends on your python version. If you use python 2.x, you have to use a u before the string: s = u'Hallo World' Ok. So, let's go back to my first question: s = u'Hallo World' is unicode in python 2.x -> ok s = 'Hallo World' how is encoded? Since it's a

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
Uff, encoding is a very painful thing in programming. Ok so now comes last "layer" of the encoding: the webserver. I now know how to handle encoding in a python app and in interactions with the db, but the last step is sending the content to the webserver. How should i encode pages? The encoding

Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin
Giorgio wrote: Depends on your python version. If you use python 2.x, you have to use a u before the string: s = u'Hallo World' Ok. So, let's go back to my first question: s = u'Hallo World' is unicode in python 2.x -> ok s = 'Hallo World' how is encoded? I am not 100% sure,

Re: [Tutor] Encoding

2010-03-03 Thread Stefan Behnel
Giorgio, 03.03.2010 15:50: Depends on your python version. If you use python 2.x, you have to use a u before the string: s = u'Hallo World' Ok. So, let's go back to my first question: s = u'Hallo World' is unicode in python 2.x -> ok Correct. s = 'Hallo World' how is encoded? Depend

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
> > >> Depends on your python version. If you use python 2.x, you have to use a > u before the string: > > s = u'Hallo World' Ok. So, let's go back to my first question: s = u'Hallo World' is unicode in python 2.x -> ok s = 'Hallo World' how is encoded? >> I think the encoding of the db doesn

Re: [Tutor] Encoding

2010-03-03 Thread Stefan Behnel
Giorgio, 03.03.2010 14:09: byte_string = unicode_string.encode('utf-8') If you use unicode strings throughout your application, you will be happy with the above. Note that this is an advice, not a condition. Mmm ok. So all strings in the app are unicode by default? Do you know if there is

Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin
Mmm ok. So all strings in the app are unicode by default? Depends on your python version. If you use python 2.x, you have to use a u before the string: s = u'Hallo World' Do you know if there is a function/method i can use to check encoding of a string? AFAIK such a function doesn't exis

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
Oh, sorry, let me update my last post: if i have a string, let's say: s = "hi giorgio"; and want to store it in a latin1 db, i need to convert it to latin1 before storing, right? 2010/3/3 Giorgio > >>> byte_string = unicode_string.encode('utf-8') >> >> If you use unicode strings throughout y

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
> > >> byte_string = unicode_string.encode('utf-8') > > If you use unicode strings throughout your application, you will be happy > with the above. Note that this is an advice, not a condition. Mmm ok. So all strings in the app are unicode by default? Do you know if there is a function/method

Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin
Giorgio wrote: i am looking for more informations about encoding in python: i've read that Amazon SimpleDB accepts every string encoded in UTF-8. How can I encode a string? And, what's the default string encoding in python? I think the safest way is to use unicode strings in your application

Re: [Tutor] Encoding

2010-03-03 Thread Stefan Behnel
Giorgio, 03.03.2010 09:36: i am looking for more informations about encoding in python: i've read that Amazon SimpleDB accepts every string encoded in UTF-8. How can I encode a string? byte_string = unicode_string.encode('utf-8') If you use unicode strings throughout your application, you w

Re: [Tutor] Encoding question

2009-09-09 Thread Kent Johnson
On Wed, Sep 9, 2009 at 5:06 AM, Oleg Oltar wrote: > Hi! > > One of my tests returned following text () > > The test: > from django.test.client import Client >  c = Client() > resp = c.get("/") > resp.content > > In [25]: resp.content > Out[25]: '\r\n\r\n\r\n Strict//EN" > "http://www.w3.org/TR/xht

Re: [Tutor] Encoding and Decoding

2007-01-02 Thread Carlos
Kent, Will give this a try. Thanks for your help, Carlos Kent Johnson wrote: > OK, off the top of my head (not tested) here are some things to get > you started. > > You could write a function that would retrieve a coordinate value > given an index number, for example: > def getCoord(data, i

Re: [Tutor] Encoding and Decoding

2007-01-02 Thread Kent Johnson
Carlos wrote: > Hi Kent, > > I have yet to get into OO, and the GA that I'm using was done in this > way, so I can't mess with it that much. So for now yes, the list has to > be a flat element containing all this info. > > I have been reading about OO lately and a element class seems to be a >

Re: [Tutor] Encoding and Decoding

2007-01-02 Thread Carlos
Hi Kent, I have yet to get into OO, and the GA that I'm using was done in this way, so I can't mess with it that much. So for now yes, the list has to be a flat element containing all this info. I have been reading about OO lately and a element class seems to be a good idea, I'm working on it

Re: [Tutor] Encoding and Decoding

2007-01-02 Thread Kent Johnson
Carlos wrote: > The genetic algorithm that Im using (GA) generates solutions for a given > problem, expressed in a list, this list is composed by integers. Every > element in the list takes 8 integers, is a little messy but this is because > > List [0] = Tens X position > List [1] = Units X pos

Re: [Tutor] Encoding and XML troubles

2006-11-08 Thread Danny Yoo
Vanilla (this works fine): #!/usr/bin/python from elementtree import ElementTree as etree eg = """redblue""" xml = etree.fromstring(eg) If I change the example string to this: redblu� I get the following error: xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 32)

Re: [Tutor] Encoding and XML troubles

2006-11-08 Thread William O'Higgins Witteman
Thanks for the help thusfar. To recap - when parsing XML, ElementTree is barfing on extended characters. 1. Yes, most XML is written by monkeys, or the programs written by such monkeys - tough beans, I cannot make my input XML any cleaner without pre-processing - I am not generating it. 2. The d

Re: [Tutor] Encoding and XML troubles

2006-11-05 Thread Dustin J. Mitchell
For what it's worth, the vast majority of the XML out there (especially if you're parsing RSS feeds, etc.) is written by monkeys and is totally ill-formed. It seems the days of 'it looked OK in my browser' are still here. To find out if it's your app or the XML, you could try running the XML thro

Re: [Tutor] Encoding and XML troubles

2006-11-05 Thread Kent Johnson
William O'Higgins Witteman wrote: > I've been struggling with encodings in my XML input to Python programs. > > Here's the situation - my program has no declared encoding, so it > defaults to ASCII. It's written in Unicode, but apparently that isn't > confusing to the parser. Fine by me. I impo

Re: [Tutor] Encoding and XML troubles

2006-11-04 Thread Luke Paireepinart
Inputting XML into a Python program has nothing to do with what encoding the python source is in.So it seems to me that that particular PEP doesn't apply in this case at all.I'm guessing that the ElementTree module has an option to use Unicode input. ___

Re: [Tutor] encoding text in html

2006-09-13 Thread Danny Yoo
On Wed, 13 Sep 2006, anil maran wrote: > > i was trying to display some text it is in utf-8 in postgres and when it > is displayed in firefox and ie, it gets displayed as some symols with > 4numbers in a box or so even for ' apostrophe please tell me how to > display this properly i try title

Re: [Tutor] encoding text in html

2006-09-13 Thread Kent Johnson
anil maran wrote: > > > i was trying to display some text > it is in utf-8 in postgres and when it is displayed in firefox and ie, > it gets displayed as some symols with 4numbers in a box or so > even for ' apostrophe > please tell me how to display this properly > i try > title.__str__ > > or

Re: [Tutor] encoding text in html

2006-09-13 Thread Kent Johnson
as it displays? Kent > > - Original Message > From: anil maran <[EMAIL PROTECTED]> > To: anil maran <[EMAIL PROTECTED]> > Sent: Wednesday, September 13, 2006 2:07:55 AM > Subject: Re: [Tutor] encoding text in html > > > > submits: We\xe2\x80\x99re prett

Re: [Tutor] encoding text in html

2006-09-13 Thread anil maran
「ひぐらしのなく頃に」30秒TVCF風ver.0.1 this is how it is getting displayed in browser- Original Message From: anil maran <[EMAIL PROTECTED]>To: anil maran <[EMAIL PROTECTED]>Sent: Wednesday, September 13, 2006 2:07:55 AMSubject: Re: [Tutor] encoding text in htmlsubmits: We\x

Re: [Tutor] encoding text in html

2006-09-13 Thread anil maran
submits: We\xe2\x80\x99re pretty surthis is how it is stored in postgresplease help me outthanks- Original Message From: anil maran <[EMAIL PROTECTED]>To: tutor@python.orgSent: Wednesday, September 13, 2006 12:14:10 AMSubject: encoding text in html i was trying to display some text it is in

Re: [Tutor] encoding

2006-09-11 Thread Kent Johnson
Jose P wrote: > watch this example: > a=['lula', 'cação'] print a > ['lula', 'ca\xc3\xa7\xc3\xa3o'] print a[1] > cação > > > when i print the list the special characters are not printed correctly! When you print a list, it uses repr() to format the contents of the list; when yo

Re: [Tutor] encoding

2006-04-12 Thread Hugo González Monteverde
kakada wrote: > LookupError: unknown encoding: ANSI > > so what is the correct way to do it? > stringinput.encode('latin_1') works for me. Do a Google search for Python encodings, and you will find what the right names for the encodings are. http://docs.python.org/lib/standard-encodings.ht