473,516 Members | 3,327 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Documentation for "str()" could use some adjustment.

The Python documentation for "str" says
"str([object]) :
Return a string containing a nicely printable representation of an object."

However, there's no mention of the fact that "str" of a Unicode string
with non-ASCII characters will raise a conversion exception. The
documentation (and several Python books) seem to indicate that "str" will
produce some "printable representation" for anything, not raise an exception.

I know, it was proposed in PEP 349 to change "str" to return Unicode
strings, and that's coming someday, along with all-Unicode Python,
but meanwhile, the documentation should be clear about this.

John Nagle
Mar 19 '07 #1
8 1411
The Python documentation for "str" says
"str([object]) :
Return a string containing a nicely printable representation of an
object."

However, there's no mention of the fact that "str" of a Unicode string
with non-ASCII characters will raise a conversion exception. The
documentation (and several Python books) seem to indicate that "str" will
produce some "printable representation" for anything, not raise an
exception.

I know, it was proposed in PEP 349 to change "str" to return Unicode
strings, and that's coming someday, along with all-Unicode Python,
but meanwhile, the documentation should be clear about this.
Hi John, I'm not at all an expert around here but my understanding of
the workflow is that bug reports should be submitted to the tracker at
sourceforge. There is no guarantee that they will be noticed there but
the chances there are much higher than for a message on the mailing
list. I just mention this because I've seen your mysqld, urllib and
other potentially important bug reports here with no action taken but
maybe submitting them to sourceforge would attract some developers.
Mar 19 '07 #2
Daniel Nogradi wrote:
>The Python documentation for "str" says
"str([object]) :
Return a string containing a nicely printable representation of an
object."

However, there's no mention of the fact that "str" of a Unicode string
with non-ASCII characters will raise a conversion exception. The
documentation (and several Python books) seem to indicate that "str" will
produce some "printable representation" for anything, not raise an
exception.

I know, it was proposed in PEP 349 to change "str" to return Unicode
strings, and that's coming someday, along with all-Unicode Python,
but meanwhile, the documentation should be clear about this.


Hi John, I'm not at all an expert around here but my understanding of
the workflow is that bug reports should be submitted to the tracker at
sourceforge. There is no guarantee that they will be noticed there but
the chances there are much higher than for a message on the mailing
list. I just mention this because I've seen your mysqld, urllib and
other potentially important bug reports here with no action taken but
maybe submitting them to sourceforge would attract some developers.
More people read the mailing list than the bug reports, and
Google indexes it, so it puts the problem on record. If this problem
were reported as a bug, there'd be denial that it was a problem, on
the grounds that it will be fixed in a future version of Python.

This was addressed in PEP 349 (status "Deferred"), so it's
a known problem that's being ignored.

Python strings are in transition; in ASCII-only Python, "str"
could never raise a conversion exception, and when we get to
Unicode-only strings, "str" will never raise a conversion exception.
But right now, "str" can definitely raise an exception.

The real problem is the published books on Python:

"Learning Python", by Lutz and Ascher:
"str(string) -- returns the string representation of any object."

"Python in a Nutshell", by Martelli
Doesn't really address the issue, but says that "print" calls
"str" for conversions.

Neither of these mentions that "str" is ASCII-only.

I think that you can use "unicode()" on any object on
which you can use "str()", but I'm not sure that's official.

Incidentally, is "repr" ASCII-only, or does it understand
Unicode? And what happens if the __str__() method of an object
returns Unicode?

John Nagle
Mar 19 '07 #3

"John Nagle" <na***@animats.comwrote in message
news:Xn******************@newssvr21.news.prodigy.n et...
| The Python documentation for "str" says
| "str([object]) :
| Return a string containing a nicely printable representation of an
object."
|
| However, there's no mention of the fact that "str" of a Unicode string
| with non-ASCII characters will raise a conversion exception. The
| documentation (and several Python books) seem to indicate that "str" will
| produce some "printable representation" for anything, not raise an
exception.
|
| I know, it was proposed in PEP 349 to change "str" to return Unicode
| strings, and that's coming someday, along with all-Unicode Python,
| but meanwhile, the documentation should be clear about this.

I agree. Formulate a concise sentence and submit it as a doc patch on SF.
No need for a separate file -- just put it in the report box along with the
section where the change goes and an explanation and example of the
exception raised. If accepted, a doc maintainer will put it in the Latex
source.

tjr

Mar 19 '07 #4
John Nagle wrote:
and when we get to
Unicode-only strings, "str" will never raise a conversion exception.
On *strings*, maybe, but objects can implement __str__ in
arbitrary ways, so you can't say anything in general about
what str() will do.

--
Greg
Mar 20 '07 #5
On Mon, 19 Mar 2007 17:01:23 +0000, John Nagle wrote:
>Hi John, I'm not at all an expert around here but my understanding of
the workflow is that bug reports should be submitted to the tracker at
sourceforge. There is no guarantee that they will be noticed there but
the chances there are much higher than for a message on the mailing
list. I just mention this because I've seen your mysqld, urllib and
other potentially important bug reports here with no action taken but
maybe submitting them to sourceforge would attract some developers.

More people read the mailing list than the bug reports, and
Google indexes it, so it puts the problem on record.
"More people" is irrelevant. What matters is "the right people".

I believe Google also indexes bug reports. It depends whether the site
allows Google's spiders or not.

If this problem
were reported as a bug, there'd be denial that it was a problem, on
the grounds that it will be fixed in a future version of Python.
I don't think so much it's denied as that the developers have decided
that fixing it isn't a valuable use of their time because there are more
important (or more interesting) problems that they could be fixing
instead, and it will go away on its own with Python 3.

This was addressed in PEP 349 (status "Deferred"), so it's
a known problem that's being ignored.
Then stop ignoring it, and submit a fix!

If you personally don't have the time or expertise to fix the problem
yourself, pay somebody to do so. Who says Open Source isn't compatible
with capitalism?

--
Steven.

Mar 20 '07 #6
John Nagle <na***@animats.comwrote:
...
The real problem is the published books on Python:

"Learning Python", by Lutz and Ascher:
"str(string) -- returns the string representation of any object."

"Python in a Nutshell", by Martelli
Doesn't really address the issue, but says that "print" calls
"str" for conversions.

Neither of these mentions that "str" is ASCII-only.
Are you looking at p. 109 of the 2nd edition of the Nutshell? That's
where looking for str will eventually lead you. The word "ASCII" is
nowhere in sight in this page (because it's only true if you don't
change the default encoding, so saying "str is ASCII-only" would be a
lie -- now THAT kind of disinformation WOULD be a "real problem" in a
"published book on Python") but right after the documentation for
__str__ you see that for __unicode__ which explains their respective
roles (returning plain-string types and unicode strings respectively).

Unicode is documented on page 198 ff, where you will clearly see that:
"""
Python uses a default encoding, normally 'ascii'.
"""
followed by pointers to modules and functions connected with changing
that default, and a recommendation to avoid doing that and why.

I therefore dispute your contention that "Python in a Nutshell"
``doesn't really address the issue", as well as your other contention
that "the real problem is" my book (I won't speak for Lutz and Ascher).

If you disagree, feel free to open an errata on O'Reilly's page devoted
to my book (and/or to the one by Lutz and Ascher); I will of course do
my best to strongly rebut your provably-false contentions, if it's my
book you choose to attack (I use the word advisedly, because it's easy
to see that you're not interested in offering constructive criticism and
suggestions -- it would have been obvious to open an errata, had you
been thus interested -- but only in picking a public fight about this).
Alex
Mar 20 '07 #7
Alex Martelli wrote:
John Nagle <na***@animats.comwrote:
...
> The real problem is the published books on Python:

"Learning Python", by Lutz and Ascher:
"str(string) -- returns the string representation of any object."

"Python in a Nutshell", by Martelli
Doesn't really address the issue, but says that "print" calls
"str" for conversions.

Neither of these mentions that "str" is ASCII-only.


Are you looking at p. 109 of the 2nd edition of the Nutshell?
No, I'm looking at the original edition from 2003. That
was what Borders had in stock late last year.

John Nagle
Mar 20 '07 #8
John Nagle <na***@animats.comwrote:
...
Are you looking at p. 109 of the 2nd edition of the Nutshell?

No, I'm looking at the original edition from 2003. That
was what Borders had in stock late last year.
Eeek -- the 2nd edition came out in July 2006, and several months later
Borders were STILL stocking the older, long-out-of-print one?!

I occasionally checked this summer and the Palo Alto and Sunnyvale
locations of Borders did seem to upgrade reasonably fast -- but maybe
that's just a Silicon Valley thing...?
Alex
Mar 21 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2428
by: Jim Hefferon | last post by:
Hello, I'm getting an error join-ing strings and wonder if someone can explain why the function is behaving this way? If I .join in a string that contains a high character then I get an ascii codec decoding error. (The code below illustrates.) Why doesn't it just concatenate? I'm building up a web page by stuffing an array and then...
7
1900
by: Jeffrey E. Forcier | last post by:
I am attempting to write a class whose string representation changes in response to external stimuli. While that effect is obviously possible via other means, I attempted this method first and was surprised when it didn't work, so I now want to know why :) Given the following class definition: class MyClass(object): def Edit(self):
13
2999
by: José Joye | last post by:
The example at the end make me perplex... Looking at the msdn documentation, the inheritance tree that relates to "delegate" is as follow: Object<--Delegate<--MulticastDelegate. Unless I'm blind, there is no "+" operator as well for this class. To be able to combine delegates, I thought we should use either MulticastDelegate or event.
1
1585
by: Burkhard Perkens-Golomb | last post by:
Hi, I've a question about XML documentation of overridding methods and methods implementing an interface declaration: These methods are normally documented in the base class or interface. So I don't want to write new documentation when overriding or implementing. But if I leave out documentation and compile my assembly with "/doc" the...
1
2039
by: ScottyO | last post by:
Hello, I have some legacy C++ code that was re-written as a managed class. I made a C++ class library with it and I want to use it in my C# program. I created a reference to it and it instantiates the object ok, but when I go to use one of it's methods I have a problem. The method requires a "basic_string" from the std library. I do...
2
2418
by: john | last post by:
In a query I have this expression: Expr1: "ZH"+Str() It should give me ZH1234 but it adds a space between the 2 parts so I get ZH 1234. What can I do to prevent this? Thanks, john
1
1887
by: bcwhite | last post by:
I'm writing a program and want to create a class that is derived from the "str" base type. When I do so, however, I have problems with the __init__ method. When I run the code below, it will call my new __init__ method when there is zero or one (value) parameter. However, if I try to pass two parameters or a named parameter, then it dies...
3
1574
by: Ge Chunyuan | last post by:
hi Group: Once use ActivePython latest version for Python 2.5.1. I happened to find function "str" is not callable, but it is available for Python 2.5. Can anybody give some comments about it? Any response is highly appreciated.
7
1410
by: Anita Kean | last post by:
Hello I just downloaded the new python2.6 documentation, full of hopes it would solve some basic mysteries for me. I'm new to python, so please forgive my ignorance. I've two questions. 1) Everywhere in the old and new documentation, the string of characters "::=" is used in "explaining" things - but I can nowhere find any stated...
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.