[Python-Dev] datetime.date.today() raises "AttributeError: time"
For an unknown reason, datetime.date.today() began throwing a cryptic "AttributeError: time" exception. It took me a while to figure out that this was caused by an accidental overriding of the built-in 'time' module. Here's an example interactive session which shows the problem: [tal ~]$ touch time.py [tal ~]$ python Python 2.5.2 (r252:60911, Jul 17 2008, 10:47:50) [GCC 4.0.1 (Apple Inc. build 5484)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.__file__ 'time.py' >>> import datetime >>> datetime.date.today() Traceback (most recent call last): File "", line 1, in AttributeError: time >>> Here I used version 2.5.2, but I checked and this also happens on 2.6. It this desired behavior? At the very least the exception should be more detailed, perhaps to the point of suggesting the probable cause of the error (i.e. overriding the time module). - Tal ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] datetime.date.today() raises "AttributeError: time"
Tal Einat wrote: > For an unknown reason, datetime.date.today() began throwing a cryptic > "AttributeError: time" exception. It took me a while to figure out > that this was caused by an accidental overriding of the built-in > 'time' module. > > Here's an example interactive session which shows the problem: > > [tal ~]$ touch time.py > [tal ~]$ python > Python 2.5.2 (r252:60911, Jul 17 2008, 10:47:50) > [GCC 4.0.1 (Apple Inc. build 5484)] on darwin > Type "help", "copyright", "credits" or "license" for more information. import time time.__file__ > 'time.py' import datetime datetime.date.today() > Traceback (most recent call last): > File "", line 1, in > AttributeError: time > > Here I used version 2.5.2, but I checked and this also happens on 2.6. > > > It this desired behavior? > > At the very least the exception should be more detailed, perhaps to > the point of suggesting the probable cause of the error (i.e. > overriding the time module). > How is this different from any other case where you import a module with a standard library name conflict, thereby confusing modules loaded later standard library. Should we do the same for any error induced in such a way? regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] datetime.date.today() raises "AttributeError: time"
Steve Holden wrote: > Tal Einat wrote: >> It this desired behavior? >> >> At the very least the exception should be more detailed, perhaps to >> the point of suggesting the probable cause of the error (i.e. >> overriding the time module). >> > How is this different from any other case where you import a module with > a standard library name conflict, thereby confusing modules loaded later > standard library. Should we do the same for any error induced in such a way? The difference is that here the exception is generated directly in the C code so you don't get an intelligible traceback. The C code for datetime imports the time module via the Python C API. In other words, here a function from a module in the stdlib, datetime, barfs unexpectedly because I happen to have a file name time.py hanging around in some directory. There is no traceback and no intelligible exception message, just "AttributeError: time". I had to dig through datetime's C code to figure out which module was being imported via the Python C API, which turned out to be time. This is rare enough that I've never had something like this happen to me in seven years of heavy Python programming. - Tal ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Summaries for Number 2008, First Half
Thanks for getting back to this! On Sun, Nov 16, 2008, Calvin Spealman wrote: > > --- > Optionally using GMP to implement long if available > --- I'd combine the long optimization thread here -- I don't see any reason for separate thread summaries. Or at least put them next to each other. > --- > hg branch gone? > --- I'd skip this thread > -- > My patches > -- The summary should use clear titles, especially if they don't have an actual summary for a thread. I'd title this "How do I get my patches accepted?" or "Can someone please look at my patches?" -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ "It is easier to optimize correct code than to correct optimized code." --Bill Harlan ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] datetime.date.today() raises "AttributeError: time"
On Sun, Nov 16, 2008 at 11:55 AM, Tal Einat <[EMAIL PROTECTED]> wrote: > Steve Holden wrote: >> Tal Einat wrote: >>> It this desired behavior? >>> >>> At the very least the exception should be more detailed, perhaps to >>> the point of suggesting the probable cause of the error (i.e. >>> overriding the time module). >>> >> How is this different from any other case where you import a module with >> a standard library name conflict, thereby confusing modules loaded later >> standard library. Should we do the same for any error induced in such a way? > > The difference is that here the exception is generated directly in the > C code so you don't get an intelligible traceback. The C code for > datetime imports the time module via the Python C API. > > In other words, here a function from a module in the stdlib, datetime, > barfs unexpectedly because I happen to have a file name time.py > hanging around in some directory. There is no traceback and no > intelligible exception message, just "AttributeError: time". I had to > dig through datetime's C code to figure out which module was being > imported via the Python C API, which turned out to be time. Just like Steve told you, this isn't different from other cases. But, at least you get a message a bit more verbose in most cases, like: Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'time' Then I went to look why this wasn't happening with datetime too, and I found out that PyObject_CallMethod in abstract.c re sets the exception message that would have been set by PyObject_GetAttr by now. Maybe someone can tell me why it is doing that, for now a patch is attached here (I didn't resist to not remove two trailing whitespaces). > > This is rare enough that I've never had something like this happen to > me in seven years of heavy Python programming. > > - Tal > ___ > Python-Dev mailing list > Python-Dev@python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > http://mail.python.org/mailman/options/python-dev/ggpolo%40gmail.com > -- -- Guilherme H. Polo Goncalves Index: Objects/abstract.c === --- Objects/abstract.c (revision 67226) +++ Objects/abstract.c (working copy) @@ -2575,13 +2575,11 @@ return null_error(); func = PyObject_GetAttrString(o, name); - if (func == NULL) { - PyErr_SetString(PyExc_AttributeError, name); - return 0; - } + if (func == NULL) + return NULL; if (!PyCallable_Check(func)) { - type_error("attribute of type '%.200s' is not callable", func); + type_error("attribute of type '%.200s' is not callable", func); goto exit; } @@ -2614,13 +2612,11 @@ return null_error(); func = PyObject_GetAttrString(o, name); - if (func == NULL) { - PyErr_SetString(PyExc_AttributeError, name); - return 0; - } + if (func == NULL) + return NULL; if (!PyCallable_Check(func)) { - type_error("attribute of type '%.200s' is not callable", func); + type_error("attribute of type '%.200s' is not callable", func); goto exit; } ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
[Python-Dev] How to read fonts in python
Hello to all, I am writing a program in python to convert Indic true type fonts in Unicode. I like to know is there any way to read the fonts and on the basis of that i can use map file to convert the font in unicode. Please help me. regards, Ginovation ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com