Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16704

Re: Scope of variable inside list comprehensions?

From Rainer Grimm <r.grimm@science-computing.de>
Newsgroups comp.lang.python
Subject Re: Scope of variable inside list comprehensions?
Date 2011-12-05 22:42 -0800
Organization http://groups.google.com
Message-ID <11334186.28.1323153755482.JavaMail.geo-discussion-forums@vbxw7> (permalink)
References <25531460.861.1323104692320.JavaMail.geo-discussion-forums@yqiv14>

Show all headers | View raw


Hello,

>     try:
>         songs = [Song(id) for id in song_ids]
>     except Song.DoesNotExist:
>         print "unknown song id (%d)" % id
that's is a bad programming style. So it will be forbidden with python 3. The reason is that list comprehension is a construct from the functional world. It's only syntactic sugar for the functions map and filter. So functions have to be pure functions. To say it in other words, they have to be side-effect free. But the python construct from above pollutes the namespace with name id.

Greetings from Rottenburg,
Rainer

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 09:04 -0800
  Re: Scope of variable inside list comprehensions? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-12-05 20:04 +0200
  Re: Scope of variable inside list comprehensions? Peter Otten <__peter__@web.de> - 2011-12-05 19:10 +0100
  Re: Scope of variable inside list comprehensions? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-05 19:57 +0100
    Re: Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 11:15 -0800
    Re: Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 11:15 -0800
      Re: Scope of variable inside list comprehensions? Terry Reedy <tjreedy@udel.edu> - 2011-12-05 15:22 -0500
        Re: Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 14:36 -0800
        Re: Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 14:36 -0800
          Re: Scope of variable inside list comprehensions? Terry Reedy <tjreedy@udel.edu> - 2011-12-05 21:23 -0500
    Re: Scope of variable inside list comprehensions? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-05 22:35 +0000
      Re: Scope of variable inside list comprehensions? Roy Smith <roy@panix.com> - 2011-12-05 14:57 -0800
        Re: Scope of variable inside list comprehensions? Chris Angelico <rosuav@gmail.com> - 2011-12-06 13:35 +1100
      Re: Scope of variable inside list comprehensions? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-06 11:38 +0100
  Re: Scope of variable inside list comprehensions? Rainer Grimm <r.grimm@science-computing.de> - 2011-12-05 22:42 -0800
    Re: Scope of variable inside list comprehensions? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-06 02:16 -0800

csiph-web