I've come across a couple of 'features' in Python standard libraries -
and I'm not sure if they're meant to be there... or if they're bugs...
One in urllib2 and one in cgi. from urllib2 import urlopen a = urlopen('http://www.voidspace.org.uk') i = a.info() for entry in i: print entry
Traceback (most recent call last):
File "<pyshell#11>", line 1, in -toplevel-
for entry in i: print entry
File "D:\PYTHON23\lib\rfc822.py", line 390, in __getitem__
return self.dict[name.lower()]
AttributeError: 'int' object has no attribute 'lower'
and in cgi (a result that happens in live CGI as well as interactive
sessions....) :
import cgi a = cgi.FieldStorage() for entry in a: print entry
Traceback (most recent call last):
File "<pyshell#3>", line 1, in ?
for entry in a: print entry
File "C:\PYTHON22\lib\cgi.py", line 550, in __getitem_
raise KeyError,
keyKeyError: 0
You can get round the cgi bug because :
for entry in a.keys(): print entry
works fine - but it's a bit annoying.
(Admittedly my server has python 2.2, but the urllib2 bug occurs in
Python 2.3.4 as well I think).
Regards,
Fuzzy http://www.voidspace.org.uk/atlantib...thonutils.html 5 1757
Michael Foord <fu******@gmail.com> wrote: I've come across a couple of 'features' in Python standard libraries - and I'm not sure if they're meant to be there... or if they're bugs...
One in urllib2 and one in cgi.
from urllib2 import urlopen a = urlopen('http://www.voidspace.org.uk') i = a.info() for entry in i: print entry Traceback (most recent call last): File "<pyshell#11>", line 1, in -toplevel- for entry in i: print entry File "D:\PYTHON23\lib\rfc822.py", line 390, in __getitem__ return self.dict[name.lower()] AttributeError: 'int' object has no attribute 'lower'
Note that the problem was in rfc822 -- urllib2 was just giving you an
rfc822 message object, which then got erroneously identified as a
sequence in the implicit iter() call in the for statement. and in cgi (a result that happens in live CGI as well as interactive sessions....) : import cgi a = cgi.FieldStorage() for entry in a: print entry Traceback (most recent call last): File "<pyshell#3>", line 1, in ? for entry in a: print entry File "C:\PYTHON22\lib\cgi.py", line 550, in __getitem_ raise KeyError, keyKeyError: 0
You can get round the cgi bug because : for entry in a.keys(): print entry works fine - but it's a bit annoying.
(Admittedly my server has python 2.2, but the urllib2 bug occurs in Python 2.3.4 as well I think).
Yes, 2.3 fixed the problem with cgi.fieldstorage (by adding an __iter__
that just returns iter(self.keys())...!-) but even 2.4 alpha 3 still has
the problem with rfc822 (which could and IMHO should be fixed similarly,
returning an iter(self.dict) from the __iter__ method).
If you post the rfc822 bug to the Python bug tracker it can probably get
fixed soon (of course it will need a new 2.3 release to get the fix out,
but at least 2.4 beta 1 won't have the problem any more).
Alex
"Michael Foord" <fu******@gmail.com> wrote in message
news:6f**************************@posting.google.c om... I've come across a couple of 'features' in Python standard libraries - and I'm not sure if they're meant to be there... or if they're bugs...
One in urllib2 and one in cgi.
from urllib2 import urlopen a = urlopen('http://www.voidspace.org.uk') i = a.info() for entry in i: print entry Traceback (most recent call last): File "<pyshell#11>", line 1, in -toplevel- for entry in i: print entry File "D:\PYTHON23\lib\rfc822.py", line 390, in __getitem__ return self.dict[name.lower()] AttributeError: 'int' object has no attribute 'lower'
and in cgi (a result that happens in live CGI as well as interactive sessions....) : import cgi a = cgi.FieldStorage() for entry in a: print entry Traceback (most recent call last): File "<pyshell#3>", line 1, in ? for entry in a: print entry File "C:\PYTHON22\lib\cgi.py", line 550, in __getitem_ raise KeyError, keyKeyError: 0
You can get round the cgi bug because : for entry in a.keys(): print entry works fine - but it's a bit annoying.
(Admittedly my server has python 2.2, but the urllib2 bug occurs in Python 2.3.4 as well I think).
Regards,
Fuzzy
http://www.voidspace.org.uk/atlantib...thonutils.html
The urllib2 problem looks like a clone of one mentioned earlier in the email
module, which I looked into and reported as bug 1017329. You could add your
example to that, or open a new bug report. But the two should be linked
somehow, as they have the same failure mode, and very likely the same
resolution.
Looking briefly at the cgi module also shows a similar implementation gap,
but I see that FieldStorage implements __iter__, which I thought would be
used in "for entry in a" type iteration, and that failing the existence of
__iter__, then __len__ would be tried with successive calls to __getitem__
from 0 to len-1. What *is* the order of resolution for iterating over a
sequence?
(1015249 was also recently submitted, to address problems with
FieldStorage's __len__ function, should also be linked.)
-- Paul
"Paul McGuire" <pt***@austin.rr._bogus_.com> wrote in message news:<Gp******************@fe2.texas.rr.com>... "Michael Foord" <fu******@gmail.com> wrote in message news:6f**************************@posting.google.c om... I've come across a couple of 'features' in Python standard libraries - and I'm not sure if they're meant to be there... or if they're bugs...
One in urllib2 and one in cgi.
>> from urllib2 import urlopen >> a = urlopen('http://www.voidspace.org.uk') >> i = a.info() >> for entry in i: print entry Traceback (most recent call last): File "<pyshell#11>", line 1, in -toplevel- for entry in i: print entry File "D:\PYTHON23\lib\rfc822.py", line 390, in __getitem__ return self.dict[name.lower()] AttributeError: 'int' object has no attribute 'lower'
and in cgi (a result that happens in live CGI as well as interactive sessions....) :
>> import cgi >> a = cgi.FieldStorage() >> for entry in a: print entry
Traceback (most recent call last): File "<pyshell#3>", line 1, in ? for entry in a: print entry File "C:\PYTHON22\lib\cgi.py", line 550, in __getitem_ raise KeyError, keyKeyError: 0>>
You can get round the cgi bug because : for entry in a.keys(): print entry works fine - but it's a bit annoying.
(Admittedly my server has python 2.2, but the urllib2 bug occurs in Python 2.3.4 as well I think).
Regards,
Fuzzy
http://www.voidspace.org.uk/atlantib...thonutils.html
The urllib2 problem looks like a clone of one mentioned earlier in the email module, which I looked into and reported as bug 1017329. You could add your example to that, or open a new bug report. But the two should be linked somehow, as they have the same failure mode, and very likely the same resolution.
Looking briefly at the cgi module also shows a similar implementation gap, but I see that FieldStorage implements __iter__, which I thought would be used in "for entry in a" type iteration, and that failing the existence of __iter__, then __len__ would be tried with successive calls to __getitem__ from 0 to len-1. What *is* the order of resolution for iterating over a sequence?
(1015249 was also recently submitted, to address problems with FieldStorage's __len__ function, should also be linked.)
-- Paul
Yep... I think the example failure I showed for FieldStorage was
actually under Python 2.3.4 - so I'm not convinced it's fixed.
I'll raise two new bug reports but include references to the ones you
mention....
Regards,
Fuzzy http://www.voidspace.org.uk/atlantib...thonutils.html
Michael Foord wrote: Yep... I think the example failure I showed for FieldStorage was actually under Python 2.3.4 - so I'm not convinced it's fixed.
I'll raise two new bug reports but include references to the ones you mention....
I think it _is_ fixed:
Python 2.3.3 (#1, Jan 3 2004, 13:57:08)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information. import cgi for i in cgi.FieldStorage(): print i
....
(I really should update)
I suggest that you try it out under 2.3.4 *before* you file the report. I
don't think it would be polite to bother the developers with a report of a
bug that may already be fixed.
Peter
Peter Otten <__*******@web.de> wrote in message news:<ch*************@news.t-online.com>... Michael Foord wrote:
Yep... I think the example failure I showed for FieldStorage was actually under Python 2.3.4 - so I'm not convinced it's fixed.
I'll raise two new bug reports but include references to the ones you mention....
I think it _is_ fixed:
Python 2.3.3 (#1, Jan 3 2004, 13:57:08) [GCC 3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. import cgi for i in cgi.FieldStorage(): print i ...
(I really should update)
I suggest that you try it out under 2.3.4 *before* you file the report. I don't think it would be polite to bother the developers with a report of a bug that may already be fixed.
Peter
I thought I had... but in fact the 'crate' I use to access the
internet on only has Python 2.2 (which I installed for testing my CGIs
on). Looks like it *is* fixed in 2.3.4...
Thanks
Fuzzy http://www.voidspace.org.uk/atlantib...thonutils.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brandon J. Van Every |
last post by:
I'm realizing I didn't frame my question well.
What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump
up in your chair and scream "Wow! Ruby has *that*? That is SO...
|
by: Stephen C. Waterbury |
last post by:
This seems like it ought to work, according to the
description of reduce(), but it doesn't. Is this
a bug, or am I missing something?
Python 2.3.2 (#1, Oct 20 2003, 01:04:35)
on linux2
Type...
|
by: Kl |
last post by:
Hi, python is really easy to learn in my opinion. There are loads of
tutorials/books on the web talking about the most common python features.
The problem comes when they add something new to the...
|
by: Shi Mu |
last post by:
Got confused by the following code:
>>> a
>>> b
>>> c
{1: , ], 2: ]}
>>> c.append(b.sort())
>>> c
{1: , ], 2: , None]}
|
by: Anthony Baxter |
last post by:
On behalf of the Python development team and the Python community, I'm
happy to announce the first BETA release of Python 2.5.
This is an *beta* release of Python 2.5. As such, it is not...
|
by: Petr Prikryl |
last post by:
Do you think that the following could became PEP (pre PEP).
Please, read it, comment it, reformulate it,...
Abstract
Introduction of the mechanism for language extensions via
modules...
|
by: WaterWalk |
last post by:
I've just read an article "Building Robust System" by Gerald Jay
Sussman. The article is here:
http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf
In it there is a...
|
by: Barry Warsaw |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On behalf of the Python development team and the Python community, I
am happy to announce the release of Python 2.6 final. This is the...
|
by: Chris Rebert |
last post by:
Also, the docs currently seem broken.
Example: http://docs.python.org/library/weakref.html#module-weakref ,
which is linked to from the new module index page, gives a 404 error.
Cheers,
Chris...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |