Steven D'Aprano wrote:
On Mon, 05 Dec 2011 19:57:15 +0100, Jean-Michel Pichavant wrote:
The proper way to propagate information with exceptions is using the
exception itself:
try:
songs = [Song(_id) for _id in song_ids]
except Song.DoesNotExist, exc:
print exc
I'm not entire
On Tuesday, December 6, 2011 2:42:35 PM UTC+8, Rainer Grimm wrote:
> 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. T
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.
On Tue, Dec 6, 2011 at 9:57 AM, Roy Smith wrote:
> I may be in the minority here, but it doesn't bother me much that my use of
> 'id' shadows a built-in. Especially in small scopes like this, I use
> whatever variable names make the the code easiest to read and don't worry
> about shadowing bu
On 12/5/2011 5:36 PM, Roy Smith wrote:
Well, in my defense, I did ask a pretty narrow question, "Is id
guaranteed to be in scope in the print statement?".
Yes for 2.x, guaranteed no for 3.x.
If you had simply asked "Is the loop variable of a list comprehension
guaranteed to be in scope after
Sigh. I attempted to reduce this to a minimal example to focus the discussion
on the question of list comprehension variable scope. Instead I seem to have
gotten people off on other tangents. I suppose I should post more of the real
code...
song_ids = request.POST.getlist('song_id')
On Mon, 05 Dec 2011 19:57:15 +0100, Jean-Michel Pichavant wrote:
> The proper way to propagate information with exceptions is using the
> exception itself:
>
> try:
> songs = [Song(_id) for _id in song_ids]
> except Song.DoesNotExist, exc:
> print exc
I'm not entirely sure that this is
Well, in my defense, I did ask a pretty narrow question, "Is id guaranteed to
be in scope in the print statement?". While I will admit that not knowing
whether I could alter the exception, or whether id masked a builtin or not does
complexify answering some questions, those are questions I didn
On 12/5/2011 2:15 PM, Roy Smith wrote:
Hmmm, the use of id was just a simplification for the sake of
posting. The real code is a bit more complicated and used a
different variable name, but that's a good point.
As far as storing the value in the exception, unfortunately,
DoesNotExist is not my
Hmmm, the use of id was just a simplification for the sake of posting. The
real code is a bit more complicated and used a different variable name, but
that's a good point.
As far as storing the value in the exception, unfortunately, DoesNotExist is
not my exception; it comes from deep within d
Roy Smith wrote:
Consider the following django snippet. Song(id) raises DoesNotExist if the id
is unknown.
try:
songs = [Song(id) for id in song_ids]
except Song.DoesNotExist:
print "unknown song id (%d)" % id
Is id guaranteed to be in scope in the print statement? I
Roy Smith wrote:
> Consider the following django snippet. Song(id) raises DoesNotExist if
> the id is unknown.
>
> try:
> songs = [Song(id) for id in song_ids]
> except Song.DoesNotExist:
> print "unknown song id (%d)" % id
>
> Is id guaranteed to be in scope in the prin
Roy Smith writes:
> Consider the following django snippet. Song(id) raises DoesNotExist
> if the id is unknown.
>
> try:
> songs = [Song(id) for id in song_ids]
> except Song.DoesNotExist:
> print "unknown song id (%d)" % id
>
> Is id guaranteed to be in scope in the pri
On Mon, Dec 5, 2011 at 9:04 AM, Roy Smith wrote:
> Consider the following django snippet. Song(id) raises DoesNotExist if
> the id is unknown.
>
>try:
>songs = [Song(id) for id in song_ids]
>except Song.DoesNotExist:
>print "unknown song id (%d)" % id
>
> Is id guaranteed
Consider the following django snippet. Song(id) raises DoesNotExist if the id
is unknown.
try:
songs = [Song(id) for id in song_ids]
except Song.DoesNotExist:
print "unknown song id (%d)" % id
Is id guaranteed to be in scope in the print statement? I found one thread
(
On 8/20/2010 12:56 PM, M B wrote:
fre 2010-08-20 klockan 13:19 -0600 skrev Burton Samograd:
M B writes:
Hi,
dept=0
def mud():
print dept
mud()
0
def mud():
dept+=1
print dept
You should add a global statement or else python thinks a variable used
is a
fre 2010-08-20 klockan 13:19 -0600 skrev Burton Samograd:
> M B writes:
>
> > Hi,
> dept=0
> def mud():
> > print dept
> >
> >
> mud()
> > 0
> def mud():
> > dept+=1
> > print dept
>
> You should add a global statement or else python thinks a variable used
>
M B writes:
> Hi,
dept=0
def mud():
> print dept
>
>
mud()
> 0
def mud():
> dept+=1
> print dept
You should add a global statement or else python thinks a variable used
is a local:
>>> def mud():
global dept
dept+=1
print dept
-
On Aug 20, 8:25 pm, Chris Rebert wrote:
> On Fri, Aug 20, 2010 at 11:09 AM, M B wrote:
> > Hi,
> > I try to learn python.
> > I don't understand this:
>
> dept=0
>
> def mud():
> > dept+=1
> > print dept
>
> mud()
> > Traceback (most recent call last):
> > File "",
On Fri, Aug 20, 2010 at 11:09 AM, M B wrote:
> Hi,
> I try to learn python.
> I don't understand this:
dept=0
def mud():
> dept+=1
> print dept
>
mud()
> Traceback (most recent call last):
> File "", line 1, in
> mud()
> File "", line 2, in mud
> dept+=1
> U
Hi,
I try to learn python.
I don't understand this:
(running in idle)
>>> dept=0
>>> def mud():
print dept
>>> mud()
0
>>> def mud():
dept+=1
print dept
>>> mud()
Traceback (most recent call last):
File "", line 1, in
mud()
File "", line 2, in
21 matches
Mail list logo