Hi,

I'm glad you finally got it working!

On Fri, 5 Feb 2016 16:56:58 +0200
Reinis Danne <rei4...@gmail.com> wrote:

(...)
> Replacing this:
> map(self.paper.delete, items)
> 
> with this:
> for i in items:
>     self.paper.delete(i)
> 
> fixes the problem.
> 
> I don't understand why the difference. That code is equivalent in
> both cases as far as I know. Is there a bug or I'm using map()
> incorrectly?

I'm not sure about this, the behavior of map() seems to have changed in
Python3, I just tried the following with Python2 first:

$ python
Python 2.7.9 (default, Mar  1 2015, 12:57:24) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> l = ['a', 'b', 'c']
>>> def test(x):
...     print(x)
... 
>>> map(test, l)
a
b
c
[None, None, None]
>>> 

and then with Python3:

$ python3
Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> l = ['a', 'b', 'c']
>>> def test(x):
...     print(x)
... 
>>> map(test, l)
<map object at 0x7fdfcc6342b0>
>>> 

Personally I hardly ever use map(), so I never noticed that. In fact this
change is actually documented, see
https://docs.python.org/3.0/whatsnew/3.0.html#views-and-iterators-instead-of-lists
 :

"map() and filter() return iterators. If you really need a list, a quick
fix is e.g. list(map(...)), but a better fix is often to use a list
comprehension (especially when the original code uses lambda), or
rewriting the code so it doesn’t need a list at all. Particularly tricky
is map() invoked for the side effects of the function; the correct
transformation is to use a regular for loop "

Not sure what's the use of these map objects, in Python3 now you can call
the map object's __next__() method to iterate.
But for your purpose certainly the for loop is the way to go.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Intuition, however illogical, is recognized as a command prerogative.
                -- Kirk, "Obsession", stardate 3620.7
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to