On 05/07/16 01:42, Steven D'Aprano wrote:
> On Tue, Jul 05, 2016 at 12:47:27AM +0100, Alan Gauld via Tutor wrote:
>
>>> I then tried using
>>>
>>> elif keycode == 27:
>>>
>>> but this statement didn't work.
>>
>> I'm not sure why that didn't work.
>> What exactly happened? Did you get a different
On Mon, Jul 4, 2016 at 9:56 PM, Danny Yoo wrote:
> So the extra trailing comma in a 1-tuple parenthesized expression is
> just there to make it different looking, to disambiguate it from the
> use of parentheses for expression grouping.
The comma is the distinguishing element of non-empty tuple l
On Tue, Jul 05, 2016 at 12:47:27AM +0100, Alan Gauld via Tutor wrote:
> > I then tried using
> >
> > elif keycode == 27:
> >
> > but this statement didn't work.
>
> I'm not sure why that didn't work.
> What exactly happened? Did you get a different error message?
> If so what?
I expect that t
On Mon, Jul 4, 2016 at 1:38 PM, Colby Christensen
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, 37
On 04/07/16 21:38, Colby Christensen wrote:
> elif keycode in (47, 392):
> self.div()
> elif keycode in (27):
> self.clear_all()
I meant to say...
> I then tried using
>
> elif keycode == 27:
>
> but this statement didn't work.
I'm not sure why that didn't work.
What exactly happened
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 a
On 07/04/2016 03:38 PM, Colby Christensen 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.ent
On 04/07/16 21:38, Colby Christensen wrote:
> File "/home/colby/Calculator/Calculator_betaV3.py", line 110, in OnKeyPress
> elif keycode in (27):
> TypeError: argument of type 'int' is not iterable
The problem is that 'in' needs a collection to test. (27) is not a
single element tuple but j
On Sun, Jan 19, 2014 at 2:02 PM, Oscar Benjamin
wrote:
> I think that's just an editing mistake. If you replace the word "iterator"
> with "construct" then it makes sense: We have seen that the for statement is
> such a construct.
Fair enough. Thanks. But I think that it underlines the ease with
On Jan 19, 2014 6:49 PM, "Keith Winston" wrote:
>
> Well, as usual thanks for all this, it's really great. I'd worked out
> that it was a distinction between iterators and iterables, though I'm
> going to Oscar's description a few more times: most of it made sense,
> but there are subtleties.
>
>
Well, as usual thanks for all this, it's really great. I'd worked out
that it was a distinction between iterators and iterables, though I'm
going to Oscar's description a few more times: most of it made sense,
but there are subtleties.
For example, this from the Python 3.3 tutorial:
We say such a
On 19/01/14 16:18, Oscar Benjamin wrote:
It's not really that complicated. Basically range on 3.x (or xrange on
2.x) returns a range object:
Sadly though it is complicated, at least for newbies :-(
Python 3 has cleaned up much of the language from a Comp Sci point of
view but from the point
On 19 January 2014 12:55, spir wrote:
>
> 'range' ('xrange' in python2) is certainly (at least in my view) a kind of
> iterator in the latter, more general sense used in programming (some thing
> providing items one at a time); however, it does not implement python's
> iterator protocal. Thus, it
On 01/19/2014 12:24 AM, Keith Winston wrote:
On Sat, Jan 18, 2014 at 2:19 PM, eryksun wrote:
`xrange` and 3.x `range` aren't iterators. They're sequences. A
sequence implements `__len__` and `__getitem__`, which can be used to
implement an iterator, reversed iterator, and the `in` operator (i.e
On Sat, Jan 18, 2014 at 6:24 PM, Keith Winston wrote:
>
> I guess it makes sense that iter() returns a type iterator.
`iter(obj)` returns `obj.__iter__()` if the method exists and the
result is an iterator, i.e. has a `__next__` method.
Otherwise if `obj.__getitem__` exists, it returns a generic
On Sat, Jan 18, 2014 at 2:19 PM, eryksun wrote:
> `xrange` and 3.x `range` aren't iterators. They're sequences. A
> sequence implements `__len__` and `__getitem__`, which can be used to
> implement an iterator, reversed iterator, and the `in` operator (i.e.
> `__contains__`).
I'm so glad you said
On Sat, Jan 18, 2014 at 4:22 AM, Chris “Kwpolska” Warrick
wrote:
> Here is a poor man’s pure-python re-implementation of `for`:
> https://gist.github.com/Kwpolska/8488091
This will be very handy the next time I run out of for's, or have a
surplus of while's. Fairly common.
Seriously though, than
On Sat, Jan 18, 2014 at 4:22 AM, Chris “Kwpolska” Warrick
wrote:
> For Python 2, use xrange() instead to get an iterator. In Python 3,
> range() is already an iterator.
`xrange` and 3.x `range` aren't iterators. They're sequences. A
sequence implements `__len__` and `__getitem__`, which can be u
On Sat, Jan 18, 2014 at 4:50 AM, Peter Otten <__pete...@web.de> wrote:
>
> PS: There is an odd difference in the behaviour of list-comps and generator
> expressions. The latter swallow Stopiterations which is why the above
> myzip() needs the len() test:
A comprehension is building a list in a `fo
erratum:
On 01/18/2014 12:13 PM, spir wrote:
[Note, just to compare: in Lua, this little magic making builtin sequences
special does not exist. So, to iterate over all items or pairs of a Lua table,
one would write explicitely, resp.:
for key,val in pairs(t)
for item in ipairs(t)
where
On 01/18/2014 09:51 AM, Keith Winston wrote:
I don't really get iterators. I saw an interesting example on
Stackoverflow, something like
with open('workfile', 'r') as f:
for a, b, c in zip(f, f, f):
And this iterated through a, b, c assigned to 3 consecutive lines of
the file as it it
Keith Winston wrote:
> I don't really get iterators. I saw an interesting example on
> Stackoverflow, something like
>
> with open('workfile', 'r') as f:
> for a, b, c in zip(f, f, f):
>
>
> And this iterated through a, b, c assigned to 3 consecutive lines of
> the file as it iterates t
On Sat, Jan 18, 2014 at 9:51 AM, Keith Winston wrote:
> I don't really get iterators. I saw an interesting example on
> Stackoverflow, something like
>
> with open('workfile', 'r') as f:
> for a, b, c in zip(f, f, f):
>
>
> And this iterated through a, b, c assigned to 3 consecutive lines
I just wanted to say thanlk you to those who took the time to answer my
request for help. It is very much appreciated.
Bryan A Zimmer
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailm
On Mon, Oct 22, 2012 at 6:30 PM, Bryan A. Zimmer wrote:
>
> ignore1='''
>
> This program works to do what I set out to do as a first step
> BAZ 10/19/2012
>
> '''
If this isn't meant to be a module docstring, leave it where it is,
but remove the assignment to ignore1. Unassigned triple-quoted str
On 23 October 2012 01:43, Steven D'Aprano wrote:
> In general, your __iter__ method will be trivially simple:
>
> def __iter__(self):
> return self
>
> and most of the logic will be in __next__. I see your __iter__
> method is a little more complicated, but I haven't studied it
> in detail to
On 23/10/12 09:30, Bryan A. Zimmer wrote:
I know there are errors in the program, but I wanted to see if someone
can tell me something about the iterator "magic" that this program is
trying to use.
In simple terms: an iterator is a sequence of items that understands
the iterator protocol. If y
On 23/10/12 00:32, Prasad, Ramit wrote:
Most of Ramit's comments are valid, this is just a couple of additional
notes.
from Tkinter import *
This is a frowned upon import style as it can easily override existing
names. Instead use:
import Tkinter as tk # You can change "tk" to something else
Bryan A. Zimmer wrote:
> Hello, all.
>
>
> I am a long-time programmer with little experience in Python, but am
> trying to learn. The example program, attached, is a toy app with a
> GUI that merely prints out environment keys and their associated
> values.
>
> I know there are errors in the pr
29 matches
Mail list logo