Re: Printing Unicode strings in a list

2022-04-30 Thread Chris Angelico
On Sun, 1 May 2022 at 00:03, Vlastimil Brom wrote: > (Even the redundant u prefix from your python2 sample is apparently > accepted, maybe for compatibility reasons.) Yes, for compatibility reasons. It wasn't accepted in Python 3.0, but 3.3 re-added it to make porting easier. It doesn't do anythi

Re: Printing Unicode strings in a list

2022-04-30 Thread Vlastimil Brom
have good reasons for doing so and > will be moving to Python 3.x in due course. > > I have the following questions arising from the log: > > 1. Why does the second print statement not produce [ ║] or ["║"] ? > > 2. Should the second print statement produce [ ║] or [

Re: Printing Unicode strings in a list

2022-04-28 Thread Rob Cliffe via Python-list
On 28/04/2022 14:27, Stephen Tucker wrote: To Cameron Simpson, Thanks for your in-depth and helpful reply. I have noted it and will be giving it close attention when I can. The main reason why I am still using Python 2.x is that my colleagues are still using a GIS system that has a Python pro

Re: Printing Unicode strings in a list

2022-04-28 Thread Jon Ribbens via Python-list
don't have their own str converter, so fall back to repr instead, which outputs '[', followed by the repr of each list item separated by ', ', followed by ']'. > 2. Should the second print statement produce [ ║] or ["║"] ? There's certainly n

Re: Printing Unicode strings in a list

2022-04-28 Thread Stephen Tucker
> > >2. Should the second print statement produce [ ║] or ["║"] ? > > Well, to me its behaviour is correct. Do you _want_ to get your Unicode > glyph? in quotes? That is up to you. But consider: what would be sane > output if the list contained the string "], [3

Re: Printing Unicode strings in a list

2022-04-28 Thread Cameron Simpson
yph? in quotes? That is up to you. But consider: what would be sane output if the list contained the string "], [3," ? >3. Given that I want to print a list of Unicode strings so that their >characters are displayed (instead of their Unicode codepoint definitions), >is there a m

Printing Unicode strings in a list

2022-04-28 Thread Stephen Tucker
oes the second print statement not produce [ ║] or ["║"] ? 2. Should the second print statement produce [ ║] or ["║"] ? 3. Given that I want to print a list of Unicode strings so that their characters are displayed (instead of their Unicode codepoint definitions), is there a more P

Re: Unicode strings as arguments to exceptions

2014-01-16 Thread Terry Reedy
On 1/16/2014 9:16 AM, Steven D'Aprano wrote: On Thu, 16 Jan 2014 13:34:08 +0100, Ernest Adrogué wrote: Hi, There seems to be some inconsistency in the way exceptions handle Unicode strings. Yes. I believe the problem lies in the __str__ method. For example, KeyError manages to h

Re: Unicode strings as arguments to exceptions

2014-01-16 Thread Terry Reedy
On 1/16/2014 7:34 AM, Ernest Adrogué wrote: Hi, There seems to be some inconsistency in the way exceptions handle Unicode strings. For instance, KeyError seems to not have a problem with them raise KeyError('a') Traceback (most recent call last): File "", line 1, in

Re: Unicode strings as arguments to exceptions

2014-01-16 Thread Roy Smith
In article <52d7e9a0$0$2$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 16 Jan 2014 13:34:08 +0100, Ernest Adrogué wrote: > > > Hi, > > > > There seems to be some inconsistency in the way exceptions handle > > Unicode stri

Re: Unicode strings as arguments to exceptions

2014-01-16 Thread Steven D'Aprano
On Thu, 16 Jan 2014 13:34:08 +0100, Ernest Adrogué wrote: > Hi, > > There seems to be some inconsistency in the way exceptions handle > Unicode strings. Yes. I believe the problem lies in the __str__ method. For example, KeyError manages to handle Unicode, although in an ugly w

Unicode strings as arguments to exceptions

2014-01-16 Thread Ernest Adrogué
Hi, There seems to be some inconsistency in the way exceptions handle Unicode strings. For instance, KeyError seems to not have a problem with them >>> raise KeyError('a') Traceback (most recent call last): File "", line 1, in KeyError: 'a' >>

Re: split lines from stdin into a list of unicode strings

2013-09-05 Thread Kurt Mueller
Am 05.09.2013 10:33, schrieb Peter Otten: > Kurt Mueller wrote: >> Am 29.08.2013 11:12, schrieb Peter Otten: >>> kurt.alfred.muel...@gmail.com wrote: On Wednesday, August 28, 2013 1:13:36 PM UTC+2, Dave Angel wrote: > On 28/8/2013 04:32, Kurt Mueller wrote: >> For some text manipulatio

Re: split lines from stdin into a list of unicode strings

2013-09-05 Thread Peter Otten
Kurt Mueller wrote: > Am 29.08.2013 11:12, schrieb Peter Otten: >> kurt.alfred.muel...@gmail.com wrote: >>> On Wednesday, August 28, 2013 1:13:36 PM UTC+2, Dave Angel wrote: On 28/8/2013 04:32, Kurt Mueller wrote: > For some text manipulation tasks I need a template to split lines > f

Re: split lines from stdin into a list of unicode strings

2013-09-05 Thread Kurt Mueller
Am 29.08.2013 11:12, schrieb Peter Otten: > kurt.alfred.muel...@gmail.com wrote: >> On Wednesday, August 28, 2013 1:13:36 PM UTC+2, Dave Angel wrote: >>> On 28/8/2013 04:32, Kurt Mueller wrote: For some text manipulation tasks I need a template to split lines from stdin into a list of str

Re: split lines from stdin into a list of unicode strings

2013-08-29 Thread Peter Otten
Kurt Mueller wrote: > I have to say that I am a bit disapointed by the chardet library. > The encoding for the single character 'ü' > is detected as {'confidence': 0.99, 'encoding': 'EUC-JP'}, > whereas "file" says: > $ echo "ü" | file -i - > /dev/stdin: text/plain; charset=utf-8 > $ > > "ü" is a

Re: split lines from stdin into a list of unicode strings

2013-08-29 Thread Kurt Mueller
Am 29.08.2013 11:12, schrieb Peter Otten: > kurt.alfred.muel...@gmail.com wrote: >> On Wednesday, August 28, 2013 1:13:36 PM UTC+2, Dave Angel wrote: >>> On 28/8/2013 04:32, Kurt Mueller wrote: For some text manipulation tasks I need a template to split lines from stdin into a list of str

Re: split lines from stdin into a list of unicode strings

2013-08-29 Thread Peter Otten
kurt.alfred.muel...@gmail.com wrote: > On Wednesday, August 28, 2013 1:13:36 PM UTC+2, Dave Angel wrote: >> On 28/8/2013 04:32, Kurt Mueller wrote: >> > For some text manipulation tasks I need a template to split lines >> > from stdin into a list of strings the way shlex.split() does it. >> > The

Re: can't get utf8 / unicode strings from embedded python

2013-08-28 Thread David M. Cotter
Thank you for your thoughtful and thorough response. I now understand much better what you (and apparently the others) were warning me against and I will certainly consider that moving forward. I very much appreciate your help as I learn about python and embedding and all these crazy encoding

Re: split lines from stdin into a list of unicode strings

2013-08-28 Thread kurt . alfred . mueller
On Wednesday, August 28, 2013 1:13:36 PM UTC+2, Dave Angel wrote: > On 28/8/2013 04:32, Kurt Mueller wrote: > > For some text manipulation tasks I need a template to split lines > > from stdin into a list of strings the way shlex.split() does it. > > The encoding of the input can vary. > Does that

Re: can't get utf8 / unicode strings from embedded python

2013-08-28 Thread Steven D'Aprano
hat advice, not just the people here but essentially the entire Python development community responsible for adding Unicode strings to the language. Can you blame me for feeling that your reply seemed rather arrogant? In any case, I'm glad you responded with a little more restraint th

Re: split lines from stdin into a list of unicode strings

2013-08-28 Thread Dave Angel
# > #!/usr/bin/env python > # vim: set fileencoding=utf-8 : > # split lines from stdin into a list of unicode strings > # Muk 2013-08-23 > # Python 2.7.3 > > from __future__ import print_function > import sys > import shlex > import chardet Is this

split lines from stdin into a list of unicode strings

2013-08-28 Thread Kurt Mueller
he list of strings to be in unicode. Here is template.py: ## #!/usr/bin/env python # vim: set fileencoding=utf-8 : # split lines from stdin into a list of unicode strings # Muk 2013-08-2

Re: can't get utf8 / unicode strings from embedded python

2013-08-27 Thread David M. Cotter
I am very sorry that I have offended you to such a degree you feel it necessary to publicly eviscerate me. Perhaps I could have worded it like this: "So far I have not seen any troubles including unicode characters in my strings, they *seem* to be fine for my use-case. What kind of trouble ha

Re: can't get utf8 / unicode strings from embedded python

2013-08-27 Thread Steven D'Aprano
of time to introduce Unicode strings in the first place. Why bother using the official interface designed to work correctly with Unicode, when you can rely on an accident of implementation that just happens to work correctly in your environment but no guarantee it will work correctly anyw

Re: can't get utf8 / unicode strings from embedded python

2013-08-27 Thread David M. Cotter
i am already doing (3), and all is working perfectly. bytestring literals are fine, i'm not sure what this trouble is that you speak of. note that i'm not using PyRun_AnyFile(), i'm loading the script myself, assumed as utf8 (which was my original problem, i had assumed it was macRoman), then

Re: can't get utf8 / unicode strings from embedded python

2013-08-25 Thread MRAB
On 25/08/2013 23:32, David M. Cotter wrote: i got it!! OMG! so sorry for the confusion, but i learned a lot, and i can share the result: the CORRECT code *was* what i had assumed. the Python side has always been correct (no need to put "u" in front of strings, it is known that the bytes are u

Re: can't get utf8 / unicode strings from embedded python

2013-08-25 Thread David M. Cotter
i got it!! OMG! so sorry for the confusion, but i learned a lot, and i can share the result: the CORRECT code *was* what i had assumed. the Python side has always been correct (no need to put "u" in front of strings, it is known that the bytes are utf8 bytes) it was my "run script" function

Re: can't get utf8 / unicode strings from embedded python

2013-08-25 Thread David M. Cotter
frøânçïé 20: second worked: frøânçïé 20: third worked: frøânçïé 20: --- 20: --- 20: Original string: 控件 20: converting... 20: first worked: 控件 20: second worked: 控件 20: third worked: 控件 20: ------- now, given the C++ source code, this s

Re: can't get utf8 / unicode strings from embedded python

2013-08-25 Thread Terry Reedy
On 8/25/2013 1:57 PM, David M. Cotter wrote: i'm sorry this is so confusing, let me try to re-state the problem in as clear a way as i can. I have a C++ program, with very well tested unicode support. All logging is done in utf8. I have conversion routines that work flawlessly, so i can assu

Re: can't get utf8 / unicode strings from embedded python

2013-08-25 Thread Vlastimil Brom
2013/8/25 David M. Cotter : > i'm sorry this is so confusing, let me try to re-state the problem in as > clear a way as i can. > > I have a C++ program, with very well tested unicode support. All logging is > done in utf8. I have conversion routines that work flawlessly, so i can > assure you

Re: can't get utf8 / unicode strings from embedded python

2013-08-25 Thread David M. Cotter
i'm sorry this is so confusing, let me try to re-state the problem in as clear a way as i can. I have a C++ program, with very well tested unicode support. All logging is done in utf8. I have conversion routines that work flawlessly, so i can assure you there is nothing wrong with logging and

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread random832
On Sat, Aug 24, 2013, at 12:47, David M. Cotter wrote: > > What _are_ you using? > i have scripts in a file, that i am invoking into my embedded python > within a C++ program. there is no terminal involved. the "print" > statement has been redirected (via sys.stdout) to my custom print class, >

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread Benjamin Kaplan
On Sat, Aug 24, 2013 at 9:47 AM, David M. Cotter wrote: > > > What _are_ you using? > i have scripts in a file, that i am invoking into my embedded python within a > C++ program. there is no terminal involved. the "print" statement has been > redirected (via sys.stdout) to my custom print clas

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread wxjmfauth
Le samedi 24 août 2013 18:47:19 UTC+2, David M. Cotter a écrit : > > What _are_ you using? > > i have scripts in a file, that i am invoking into my embedded python within a > C++ program. there is no terminal involved. the "print" statement has been > redirected (via sys.stdout) to my custom

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread David M. Cotter
> What _are_ you using? i have scripts in a file, that i am invoking into my embedded python within a C++ program. there is no terminal involved. the "print" statement has been redirected (via sys.stdout) to my custom print class, which does not specify "encoding", so i tried the suggestion a

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread random832
On Sat, Aug 24, 2013, at 2:45, David M. Cotter wrote: > > you need to use u" ... " delimiters for Unicode, otherwise the results you > > get are completely arbitrary and depend on the encoding of your terminal. > okay, well, i'm on a mac, and not using "terminal" at all. but if i > were, it woul

Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread Dave Angel
David M. Cotter wrote: > Steven wrote: >> I see you are using Python 2 > correct > >>It's hard to say what *exactly* is happening here, because you don't explain >>how the python print statement somehow gets into your C++ Log code. Do I >>guess right that it catches stdout? > yes, i'm redirecting

Re: can't get utf8 / unicode strings from embedded python

2013-08-23 Thread David M. Cotter
> I see you are using Python 2 correct > Firstly, in Python 2, the compiler assumes that the source code is encoded in > ASCII gar, i must have been looking at doc for v3, as i thought it was all assumed to be utf8 > # -*- coding: utf-8 -*- okay, did that, still no change > you need to use u"

Re: can't get utf8 / unicode strings from embedded python

2013-08-23 Thread Steven D'Aprano
On Fri, 23 Aug 2013 13:49:23 -0700, David M. Cotter wrote: > note everything works great if i use Ascii, but: > > in my utf8-encoded script i have this: > >> print "frøânçïé" I see you are using Python 2, in which case there are probably two or three errors being made here. Firstly, in

can't get utf8 / unicode strings from embedded python

2013-08-23 Thread David M. Cotter
note everything works great if i use Ascii, but: in my utf8-encoded script i have this: > print "frøânçïé" in my embedded C++ i have this: PyObject* CPython_Script::print(PyObject *args) { PyObject*resultObjP = NULL; const char *utf8_

Re: sqlalchemy and Unicode strings: errormessage

2011-05-31 Thread Chris Angelico
ny encoding that > supports the Unicode characters used. Unicode defines characters; UTF-8 is one way (of many) to represent those characters in bytes. UTF-16 and UTF-32 are other ways of representing those characters in bytes, and internally, Python probably uses one of them - but there is no guarantee

RE: sqlalchemy and Unicode strings: errormessage

2011-05-31 Thread Prasad, Ramit
>line = unicode(line.strip(),'utf8') >and now i get really utf8-strings. It does work but i dont know why it works. >For me it looks like i change an utf8-string to an utf8-string. I would like to point out that UTF-8 is not exactly "Unicode". From what I understand, Unicode is a standard while

Re: sqlalchemy and Unicode strings: errormessage

2011-05-31 Thread Benjamin Kaplan
On Tue, May 31, 2011 at 8:45 AM, Wolfgang Meiners wrote: > Am 31.05.11 13:32, schrieb Daniel Kluev: >> On Tue, May 31, 2011 at 8:40 AM, Wolfgang Meiners >> wrote: >>> metadata = MetaData('sqlite://') >>> a_table = Table('tf_lehrer', metadata, >>>    Column('id', Integer, primary_key=True), >>>  

Re: sqlalchemy and Unicode strings: errormessage

2011-05-31 Thread Wolfgang Meiners
I just found a second method on http://docs.python.org/howto/unicode you can use tho module codecs and then simply write import codecs f = codecs.open('unicode.rst', encoding='utf-8') for line in f: print repr(line) Wolfgang -- http://mail.python.org/mailman/listinfo/python-list

Re: sqlalchemy and Unicode strings: errormessage

2011-05-31 Thread Wolfgang Meiners
Am 31.05.11 11:55, schrieb Chris Withers: > Hi Wolfgang, > > On 30/05/2011 22:40, Wolfgang Meiners wrote: >> I am trying to build an application using sqlalchemy. > > You're likely to get much better help here: > > http://www.sqlalchemy.org/support.html#mailinglist > > When you post there, make

Re: sqlalchemy and Unicode strings: errormessage

2011-05-31 Thread Wolfgang Meiners
Am 31.05.11 13:32, schrieb Daniel Kluev: > On Tue, May 31, 2011 at 8:40 AM, Wolfgang Meiners > wrote: >> metadata = MetaData('sqlite://') >> a_table = Table('tf_lehrer', metadata, >>Column('id', Integer, primary_key=True), >>Column('Kuerzel', Text), >>Column('Name', Text)) > > Use Uni

Re: sqlalchemy and Unicode strings: errormessage

2011-05-31 Thread Daniel Kluev
On Tue, May 31, 2011 at 8:40 AM, Wolfgang Meiners wrote: > metadata = MetaData('sqlite://') > a_table = Table('tf_lehrer', metadata, >    Column('id', Integer, primary_key=True), >    Column('Kuerzel', Text), >    Column('Name', Text)) Use UnicodeText instead of Text. > A_record = A_class('BUM',

Re: sqlalchemy and Unicode strings: errormessage

2011-05-31 Thread Chris Withers
Hi Wolfgang, On 30/05/2011 22:40, Wolfgang Meiners wrote: I am trying to build an application using sqlalchemy. You're likely to get much better help here: http://www.sqlalchemy.org/support.html#mailinglist When you post there, make sure you include: - what python version you're using - wha

sqlalchemy and Unicode strings: errormessage

2011-05-30 Thread Wolfgang Meiners
rror) You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings. u'INSERT INTO tf_lehrer ("Kuerzel", "Name") VAL

Re: How to concatenate unicode strings ???

2011-04-26 Thread Algis Kabaila
> > > pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r') > > > > UnicodeEncodeError: 'ascii' codec can't encode character > > u'\xf1' in position 31: ordinal not in range(128) > > > > How could

Re: How to concatenate unicode strings ???

2011-04-26 Thread Terry Reedy
On 4/26/2011 12:07 PM, Chris Rebert wrote: On Tue, Apr 26, 2011 at 8:58 AM, Ariel wrote: Hi everybody, how could I concatenate unicode strings ??? What I want to do is this: unicode('this an example language ') + unicode('español') but I get an: Traceback (most recent

Re: How to concatenate unicode strings ???

2011-04-26 Thread Jean-Michel Pichavant
Chris Rebert wrote: On Tue, Apr 26, 2011 at 8:58 AM, Ariel wrote: Hi everybody, how could I concatenate unicode strings ??? What I want to do is this: unicode('this an example language ') + unicode('español') but I get an: Traceback (most recent call last):

Re: How to concatenate unicode strings ???

2011-04-26 Thread Ariel
position 31: ordinal not in range(128) > > How could I solve that ??? > Regards > Ariel > > > On Tue, Apr 26, 2011 at 6:07 PM, Chris Rebert wrote: > >> On Tue, Apr 26, 2011 at 8:58 AM, Ariel wrote: >> > Hi everybody, how could I concatenate unic

Re: How to concatenate unicode strings ???

2011-04-26 Thread Albert Hopkins
On Tue, 2011-04-26 at 17:58 +0200, Ariel wrote: > Hi everybody, how could I concatenate unicode strings ??? > What I want to do is this: > > unicode('this an example language ') + unicode('español') > > but I get an: > Traceback (most r

Re: How to concatenate unicode strings ???

2011-04-26 Thread Ariel
') UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 31: ordinal not in range(128) How could I solve that ??? Regards Ariel On Tue, Apr 26, 2011 at 6:07 PM, Chris Rebert wrote: > On Tue, Apr 26, 2011 at 8:58 AM, Ariel wrote: > >

Re: How to concatenate unicode strings ???

2011-04-26 Thread Dan Stromberg
On Tue, Apr 26, 2011 at 8:58 AM, Ariel wrote: > Hi everybody, how could I concatenate unicode strings ??? > What I want to do is this: > > unicode('this an example language ') + unicode('español') > > but I get an: > Traceback (most recent call last): >

Re: How to concatenate unicode strings ???

2011-04-26 Thread Chris Rebert
On Tue, Apr 26, 2011 at 8:58 AM, Ariel wrote: > Hi everybody, how could I concatenate unicode strings ??? > What I want to do is this: > > unicode('this an example language ') + unicode('español') > > but I get an: > Traceback (most recent call last): >

How to concatenate unicode strings ???

2011-04-26 Thread Ariel
Hi everybody, how could I concatenate unicode strings ??? What I want to do is this: unicode('this an example language ') + unicode('español') but I get an: Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can&#x

Unicode strings

2010-02-11 Thread aabelyakov
Excellent! But what about the unicode -- http://mail.python.org/mailman/listinfo/python-list

Re: Py 3: How to switch application to Unicode strings?

2010-01-20 Thread Gnarlodious
Thanks for the help, but I am going to skip this problem because I don't need Unicode characters in a script anyway. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Py 3: How to switch application to Unicode strings?

2010-01-19 Thread Mark Tolonen
"Gnarlodious" wrote in message news:646ab38b-0710-4d31-b9e1-8a6ee7bfa...@21g2000yqj.googlegroups.com... Well, Python 3 is supposed to be all Unicode by default. I shouldn't even need to say # coding:UTF-8 Yes, in Python 3, an absence of a 'coding' line assumes UTF-8. And, the file is saved

Re: Py 3: How to switch application to Unicode strings?

2010-01-19 Thread Arnaud Delobelle
Gnarlodious writes: > Well, Python 3 is supposed to be all Unicode by default. I shouldn't > even need to say > # coding:UTF-8 > > And, the file is saved as Unicode. > When a filed is saved, shouldn't it be in a specific encoding? I don't see how you can save your file 'as unicode'. You should

Re: Py 3: How to switch application to Unicode strings?

2010-01-19 Thread Stephen Hansen
On Tue, Jan 19, 2010 at 8:16 PM, Gnarlodious wrote: > Well, Python 3 is supposed to be all Unicode by default. I shouldn't > even need to say > # coding:UTF-8 > > And, the file is saved as Unicode. > > There are many mentions of this error found by Google, but none seen > to clearly say what the

Re: Py 3: How to switch application to Unicode strings?

2010-01-19 Thread Gnarlodious
Well, Python 3 is supposed to be all Unicode by default. I shouldn't even need to say # coding:UTF-8 And, the file is saved as Unicode. There are many mentions of this error found by Google, but none seen to clearly say what the problem is or how to fix it. FYI, the problem line says: cursor.ex

Re: Py 3: How to switch application to Unicode strings?

2010-01-19 Thread Mark Tolonen
you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings. So... how do I switch to Unicode? I thought I was doing it when I put # coding:utf-8 at the start of my script. All th

Re: Py 3: How to switch application to Unicode strings?

2010-01-19 Thread Stephen Hansen
hly recommended that you instead just > switch your application to Unicode strings. > > So... how do I switch to Unicode? I thought I was doing it when I put # coding:utf-8 > > at the start of my script. > All that does is mean that the script itself is encoded as utf8. In Py3,

Py 3: How to switch application to Unicode strings?

2010-01-19 Thread Gnarlodious
I am using Python 3, getting an error from SQLite: sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings

Re: How can I format unicode strings?

2009-09-09 Thread Duncan Booth
gentlestone wrote: > the error message i've got is: > > 'unicode' object has no attribute 'format' > > is the new formatting style newer then python 2.5? > > Have you tried reading the documentation? It generally tells you which version of Python introduced a feature: http://docs.python.org

Re: How can I format unicode strings?

2009-09-09 Thread Niklas Norrthon
On 9 Sep, 12:49, gentlestone wrote: > > I have python 2.5 > > return u'{0}'.format(self.name) > > doesn't work eigther > > the error message i've got is: > > 'unicode' object has no attribute 'format' > > is the new formatting style newer then python 2.5? Yes. The new string formatting appeared i

Re: How can I format unicode strings?

2009-09-09 Thread gentlestone
On 9. Sep., 12:31 h., Tim Northover wrote: > gentlestone writes: > >  return u"{}".format(self.name) > > > this one doesn't work on unicode strings. I there a not old formatting > > style possibilty for unicode strings? > > It looks like you're

Re: How can I format unicode strings?

2009-09-09 Thread Patrick Sabin
gentlestone schrieb: return u"{}".format(self.name) u"{0}".format(u"blah") works for me with python-2.6.2 Maybe your format string is wrong. - Patrick -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I format unicode strings?

2009-09-09 Thread Tim Northover
gentlestone writes: > return u"{}".format(self.name) > > this one doesn't work on unicode strings. I there a not old formatting > style possibilty for unicode strings? It looks like you're trying to mix python 3.1 and 2.6. In 2.6 you have to put a number inside

How can I format unicode strings?

2009-09-09 Thread gentlestone
return u"{}".format(self.name) this one doesn't work on unicode strings. I there a not old formatting style possibilty for unicode strings? Note: self.name can be unicode string! -- http://mail.python.org/mailman/listinfo/python-list

Re: pexpect and unicode strings

2009-09-04 Thread Sean DiZazzo
On Sep 4, 7:11 pm, Mathew Oakes wrote: > Is there anything that can be done to make pexpect spawns send unicode lines? > > In this example they are just middot characters, but this process > needs to be able to handle languages in other character sets. > > >>> spokentext = u'Nation . Search the FO

pexpect and unicode strings

2009-09-04 Thread Mathew Oakes
Is there anything that can be done to make pexpect spawns send unicode lines? In this example they are just middot characters, but this process needs to be able to handle languages in other character sets. >>> spokentext = u'Nation . Search the FOX Nation . czars \xb7 Health care >>> \xb7 t

RE: print() and unicode strings (python 3.1)

2009-08-26 Thread Anonymous
Have you considered including an encoding line at the top of your file, as described in PEP 0263: http://www.python.org/dev/peps/pep-0263/ I just ran into a similar error, but it went away when I included # coding: utf-8 as the first line in my file. -- http://mail.python.org/mailman/listinfo

Re: print() and unicode strings (python 3.1)

2009-08-26 Thread 7stud
On Aug 25, 6:34 am, Nobody wrote: > The underlying OS primitive can only handle bytes. If you read or write a > (unicode) string, Python needs to know which encoding is used. For Python > file objects created by the user (via open() etc), you can specify the > encoding; for those created by the ru

Re: print() and unicode strings (python 3.1)

2009-08-26 Thread Piet van Oostrum
> 7stud (7) wrote: >7> Thanks for the response. My OS is mac osx 10.4.11. I'm not really >7> sure how to check my locale settings. Here is some stuff I tried: >7> $ echo $LANG >7> $ echo $LC_ALL >7> $ echo $LC_CTYPE >7> $ locale >7> LANG= >7> LC_COLLATE="C" >7> LC_CTYPE="C" >7> LC_MESS

Re: print() and unicode strings (python 3.1)

2009-08-25 Thread Nobody
On Tue, 25 Aug 2009 03:41:54 -0700, 7stud wrote: > Why does echoing $LC_ALL or $LC_CTYPE just give me a blank string? Because the variables aren't set. The default locale for a particular category (e.g. LC_CTYPE) is taken from $LC_ALL if that is set, otherwise $LC_CTYPE, otherwise $LANG, otherwi

Re: print() and unicode strings (python 3.1)

2009-08-25 Thread 7stud
On Aug 24, 10:09 pm, Ned Deily wrote: > In article > , > > > > 7stud wrote: > > On Aug 24, 2:41 pm, "Martin v. Löwis" wrote: > > > > I can't figure out a way to programatically set the encoding for > > > > sys.stdout. So where does that leave me? > > > > You should be setting the terminal enco

Re: print() and unicode strings (python 3.1)

2009-08-24 Thread Ned Deily
In article , 7stud wrote: > On Aug 24, 2:41 pm, "Martin v. Löwis" wrote: > > > I can't figure out a way to programatically set the encoding for > > > sys.stdout.  So where does that leave me? > > > > You should be setting the terminal encoding administratively, not > > programmatically. > > >

Re: print() and unicode strings (python 3.1)

2009-08-24 Thread Stephen Hansen
> > > You should be setting the terminal encoding administratively, not > > programmatically. > > > > The terminal encoding has always been utf-8. It was not set > programmatically. > > It seems to me that python 3.1's string handling is broken. > Apparently, in python 3.1 I am unable to explicitl

Re: print() and unicode strings (python 3.1)

2009-08-24 Thread 7stud
On Aug 24, 2:41 pm, "Martin v. Löwis" wrote: > > I can't figure out a way to programatically set the encoding for > > sys.stdout.  So where does that leave me? > > You should be setting the terminal encoding administratively, not > programmatically. > The terminal encoding has always been utf-8.

Re: print() and unicode strings (python 3.1)

2009-08-24 Thread Martin v. Löwis
> I can't figure out a way to programatically set the encoding for > sys.stdout. So where does that leave me? You should be setting the terminal encoding administratively, not programmatically. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: print() and unicode strings (python 3.1)

2009-08-24 Thread 7stud
On Aug 24, 12:19 pm, Stefan Behnel wrote: > 7stud wrote: > > python 3.1 won't let me > > explicitly encode my unicode string > > Sure it does. But encoding a non-ASCII string to ASCII will necessarily fail. > As you should be able to see in the python 3.1 example I posted, I did not encode the st

Re: print() and unicode strings (python 3.1)

2009-08-24 Thread Stefan Behnel
7stud wrote: > python 3.1 won't let me > explicitly encode my unicode string Sure it does. But encoding a non-ASCII string to ASCII will necessarily fail. > and python 3.1 implicitly does > the encoding with the wrong codec. That's not a Python problem, though. Your terminal is configured for U

Re: print() and unicode strings (python 3.1)

2009-08-24 Thread 7stud
de string, and python 3.1 implicitly does the encoding with the wrong codec. And why would any programmer rely on python 3.1's implicit encoding of unicode strings anyway? Presumably, different systems will have different encodings for sys.stdout, some encodings might cause encode errors. -- http://mail.python.org/mailman/listinfo/python-list

Re: print() and unicode strings (python 3.1)

2009-08-24 Thread Martin v. Löwis
> I don't understand why I'm getting an encode error in python 3.1. The default encoding is not relevant here at all. Look at sys.stdout.encoding. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

print() and unicode strings (python 3.1)

2009-08-24 Thread 7stud
==python 2.6 == import sys print sys.getdefaultencoding() s = u"\u20ac" print s.encode("utf-8") $ python2.6 1test.py ascii € =python 3.1 === import sys print(sys.getdefaultencoding()) s = "€" print(s.encode("utf-8")) print(s) $ python3.1 1test.py utf-8 b'\xe2\x82\xac' Tra

Re: to use unicode strings only

2009-06-28 Thread Gaudha
On Jun 27, 9:44 pm, Benjamin Peterson wrote: > Gaudha gmail.com> writes: > > > And Peter, I tried importing the __future__ module. It's also not > > working... > > How so? Sorry guys, __future__ module is working excellent :-). I had some bad coding somewhere else, just fixed it. Anyway, thank y

Re: to use unicode strings only

2009-06-27 Thread Benjamin Peterson
Gaudha gmail.com> writes: > And Peter, I tried importing the __future__ module. It's also not > working... How so? -- http://mail.python.org/mailman/listinfo/python-list

Re: to use unicode strings only

2009-06-27 Thread Gaudha
On Jun 27, 4:54 pm, Peter Otten <__pete...@web.de> wrote: > MRAB wrote: > > Gaudha wrote: > >> I wanna make all the strings in my code unicode strings. How to do it > >> without giving unicode switch 'u' before every string? > > > Use Pytho

Re: to use unicode strings only

2009-06-27 Thread Benjamin Peterson
Gaudha gmail.com> writes: > > Hey gentlemen, > > I wanna make all the strings in my code unicode strings. How to do it > without giving unicode switch 'u' before every string? Or the -U flag, but that's probably a bad idea. -- http://mail.python.org/mailman/listinfo/python-list

Re: to use unicode strings only

2009-06-27 Thread Peter Otten
MRAB wrote: > Gaudha wrote: >> I wanna make all the strings in my code unicode strings. How to do it >> without giving unicode switch 'u' before every string? > > Use Python 3.1 instead. or use from __future__ import unicode_literals in Python 2.6. --

Re: to use unicode strings only

2009-06-27 Thread MRAB
Gaudha wrote: Hey gentlemen, I wanna make all the strings in my code unicode strings. How to do it without giving unicode switch 'u' before every string? Use Python 3.1 instead. -- http://mail.python.org/mailman/listinfo/python-list

to use unicode strings only

2009-06-27 Thread Gaudha
Hey gentlemen, I wanna make all the strings in my code unicode strings. How to do it without giving unicode switch 'u' before every string? -- http://mail.python.org/mailman/listinfo/python-list

Re: the official way of printing unicode strings

2008-12-14 Thread Martin v. Löwis
icial way of printing > unicode strings. I mean, the question is not "how can I print the unicode > string" but "how the creators of the language suppose me to print the > unicode string". I couldn't find an answer to this question in docs, so I > hope somebody

Re: the official way of printing unicode strings

2008-12-14 Thread Ben Finney
on way of > printing unicode strings? Try these: http://effbot.org/zone/unicode-objects.htm> http://www.reportlab.com/i18n/python_unicode_tutorial.html> http://www.amk.ca/python/howto/unicode> If you want something more official, try the PEP that introduced Unicode object

Re: the official way of printing unicode strings

2008-12-14 Thread J. Clifford Dyer
ally doing like that saves many problems. > Especially in Python, where there is one official way to do any elementary > task. And I just want to know what is the normal, official way of printing > unicode strings. I mean, the question is not "how can I print the unicode > string"

  1   2   3   >