[issue10836] TypeError during exception handling in urllib.request.urlretrieve

2011-01-05 Thread Alexandru Moșoi

New submission from Alexandru Moșoi :

If I try to download a inexistent file I get a TypeError which is thrown during 
exception handling.

>>> import urllib.request
>>> urllib.request.urlretrieve('missing')
Traceback (most recent call last):
  File "/usr/lib/python3.1/urllib/request.py", line 1705, in open_local_file
stats = os.stat(localname)
OSError: [Errno 2] No such file or directory: 'missing'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.1/urllib/request.py", line 133, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
  File "/usr/lib/python3.1/urllib/request.py", line 1507, in retrieve
fp = self.open_local_file(url1)
  File "/usr/lib/python3.1/urllib/request.py", line 1707, in open_local_file
raise URLError(e.errno, e.strerror, e.filename)
TypeError: __init__() takes at most 3 positional arguments (4 given)

--
components: Library (Lib)
messages: 125449
nosy: Alexandru.Moșoi
priority: normal
severity: normal
status: open
title: TypeError during exception handling in urllib.request.urlretrieve
type: behavior
versions: Python 3.1

___
Python tracker 
<http://bugs.python.org/issue10836>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9547] iterator length

2010-08-09 Thread Alexandru Moșoi

New submission from Alexandru Moșoi :

Sometimes it's useful to get the number of elements yield by an iterator. For 
example (if ilen is the name of the function):

def pi(n):
  return ilen(for e in xrange(n) if isprime(e))

def count_pred(pred, iterator):
  return ilen(itertools.ifilter(pred, iterator))

Two notable solutions are discussed here 
http://stackoverflow.com/questions/3393431/how-to-counting-not-0-elements-in-an-iterable

1) sum(1 for e in iterator)
2) len(list(iterator))

First solution is slow, the second solution uses O(N) extra memory.

I propose the addition of a new function ilen() which is functionally 
equivalent to:

def ilen(iterator):
  return sum(1 for e in iterator)

This function should be different from len() because it's time complexity is 
O(N) (most people assume that len() takes O(1)) and it consumes the iterator.

--
messages: 113421
nosy: Alexandru.Moșoi
priority: normal
severity: normal
status: open
title: iterator length
type: feature request
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3

___
Python tracker 
<http://bugs.python.org/issue9547>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com