[Tutor] iterators

Alex Hall ahall at autodist.com
Mon Jul 4 17:44:29 EDT 2016


I believe the problem is what the error says: you're passing an int. When you give it two values, you're giving it a tuple, like (1, 2). That's a list type object in Python, and the 'in' keyword has to operate on lists. Therefore, it works.

When you give it one value, though, you're giving it an integer, which isn't a list type. The 'in' keyword can't do anything with integers, so it errors out. A check for equality seems the best approach here, but, in theory, I suppose you could do

If a in [27]

To get it to work.
> On Jul 4, 2016, at 16:38, Colby Christensen <colbychristensen at hotmail.com> wrote:
> 
> I'm sure this is something simple but I'm missing it. 
> When I check the statement with two values, the if statement works. However, for the statement with one value I get an error.
> keycode = event.GetKeyCode()
> if keycode in (13, 370):
>    self.enter()
> elif keycode in (43, 388):
>    self.add()
> elif keycode in (45, 390):
>    self.sub()
> elif keycode in (42, 387):
>    self.mult()
> elif keycode in (47, 392):
>    self.div()
> elif keycode in (27):
>    self.clear_all()
> elif keycode in (67, 99):
>    self.display.SetValue('')
> else:
>    event.Skip()This is the error message.
> Traceback (most recent call last):
>   File "/home/colby/Calculator/Calculator_betaV3.py", line 110, in OnKeyPress
>     elif keycode in (27):
> TypeError: argument of type 'int' is not iterable
> 
> I then tried using
> 
> elif keycode == 27:
> 
> but this statement didn't work. 
> 
> I'm pretty sure it's something simple that I've overlooked due to my inexperience.
> 
> Thanks in advance.
> 		 	   		  
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list