[Tutor] Problem with code

2016-07-05 Thread Frank Lawrence
Hello, I have a code here that I’m having a problem with. It’s supposed to be a pizza ordering simulator, as you can tell by the title, but I keep trying to add music to it and whenever I try to play the music with the program running, it always freezes up and crashes. Can someone help me with t

Re: [Tutor] iterators

2016-07-05 Thread Alan Gauld via Tutor
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

Re: [Tutor] Problem with code

2016-07-05 Thread Alan Gauld via Tutor
On 05/07/16 04:36, Frank Lawrence wrote: > Hello, I have a code here that I’m having a problem with. Unfortunately we can't see it. Now, I could see it among a bunch of HTML when I checked it in the moderator queue, so I'm guessing you sent it as some kind of attachment and the server has stripp

[Tutor] Writing decorators?

2016-07-05 Thread Alex Hall
Hi list, I've read three or four articles on creating decorators. I don't know why, but the use of decorators makes sense, yet the creation of them isn't clicking. I get the idea, but when it comes to precisely how to write one--what goes where and gets returned/called when--it's just not making co

Re: [Tutor] Writing decorators?

2016-07-05 Thread Alan Gauld via Tutor
On 05/07/16 14:22, Alex Hall wrote: > To simplify things, what might be an example of a decorator that, say, > prints "decorated" before whatever string the decorated function prints? > My attempt would be: > > def prependDecorated(f): > def prepend(): > return "decorated"+f() > #somethi

Re: [Tutor] Writing decorators?

2016-07-05 Thread Steven D'Aprano
On Tue, Jul 05, 2016 at 09:22:52AM -0400, Alex Hall wrote: > Hi list, > I've read three or four articles on creating decorators. I don't know why, > but the use of decorators makes sense, yet the creation of them isn't > clicking. I get the idea, but when it comes to precisely how to write > one--w

Re: [Tutor] Writing decorators?

2016-07-05 Thread Alan G via Tutor
Sorry for top posting, but yes excepting you don't need the parens after log in the @log line. Sent from my Fonepad Alex Hall wrote: Okay, I think I follow. So a decorator to log that a function ran might be: import utils @log() def run(): ** #do things #util

Re: [Tutor] Writing decorators?

2016-07-05 Thread Alex Hall
On Tue, Jul 5, 2016 at 1:26 PM, Alan G wrote: > Sorry for top posting, but yes excepting you don't need the parens after > log in the @log line. > For decorators, do you never include parentheses except for passing arguments? It seems a bit odd to drop them if they'd be empty, given that anywher

Re: [Tutor] dont understand part of a code

2016-07-05 Thread Michael Selik
On Sat, Jul 2, 2016 at 8:29 AM Alan Gauld via Tutor wrote: > There are arguably easier ways of doing this > I think you'll find that for-loops are preferable to while-loops. Here's an alternative implementation. https://gist.github.com/selik/d8e0a7622ceff0fe8984a7d19d44bfca import random

[Tutor] isinstance versus 'is'?

2016-07-05 Thread Alex Hall
Hi all, Thanks for all the help regarding decorators. It makes more sense now. I was double checking that I remembered the isinstance order of arguments correctly by using the command line interpreter, and found something very odd. >>> a = 5 >>> isinstance(a, int) True >>> a is int False What ha

Re: [Tutor] isinstance versus 'is'?

2016-07-05 Thread Joel Goldstick
On Tue, Jul 5, 2016 at 3:05 PM, Alex Hall wrote: > Hi all, > Thanks for all the help regarding decorators. It makes more sense now. > > I was double checking that I remembered the isinstance order of arguments > correctly by using the command line interpreter, and found something very > odd. > >>>

Re: [Tutor] Writing decorators?

2016-07-05 Thread Alan Gauld via Tutor
On 05/07/16 18:31, Alex Hall wrote: > For decorators, do you never include parentheses except for passing > arguments? It seems a bit odd to drop them if they'd be empty, given that > anywhere else doing so would return the function object rather than call > it. Remember what the @ sign is doing

Re: [Tutor] isinstance versus 'is'?

2016-07-05 Thread Alan Gauld via Tutor
On 05/07/16 20:05, Alex Hall wrote: > I was double checking that I remembered the isinstance order of arguments > correctly by using the command line interpreter, and found something very > odd. > a = 5 isinstance(a, int) > True a is int > False > > What happened there? Don't thes

Re: [Tutor] Writing decorators?

2016-07-05 Thread Alan Gauld via Tutor
On 06/07/16 00:06, Alan Gauld via Tutor wrote: > func = decorator(func) > > If you write @decorator() > > That translates to > > @decorator()(func) Ooops, I meant to say func = decorator()(func) Sorry. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.ama

Re: [Tutor] isinstance versus 'is'?

2016-07-05 Thread Danny Yoo
On Tue, Jul 5, 2016 at 12:05 PM, Alex Hall wrote: a = 5 isinstance(a, int) > True a is int > False > > What happened there? Don't these do the same thing? I thought I could use > them interchangeably? 'isinstance' is something else from 'is'. isinstance will tell us if something

[Tutor] help with exercise 15 of zed shaw's LPTHW

2016-07-05 Thread lohecn
hey everyone. this is my first time trying this -- actually, I've been studying python only for some days now, and I'm afraid my questions are going to be rally simple, but I can't seem to understand this piece of code and thus can't move on. you probably know the book, so you know that zed

Re: [Tutor] isinstance versus 'is'?

2016-07-05 Thread Alan Gauld via Tutor
On 06/07/16 00:22, Alan Gauld via Tutor wrote: type(c) is C > True type(d) is type(C) > False The last one should of course be >>> type(d) is C False Apologies. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow

Re: [Tutor] help with exercise 15 of zed shaw's LPTHW

2016-07-05 Thread boB Stepp
Welcome! On 07/05/2016 06:56 PM, loh...@tuta.io wrote: hey everyone. this is my first time trying this -- actually, I've been studying python only for some days now, and I'm afraid my questions are going to be rally simple, but I can't seem to understand this piece of code and thus can't mov

Re: [Tutor] isinstance versus 'is'?

2016-07-05 Thread Steven D'Aprano
On Tue, Jul 05, 2016 at 03:05:45PM -0400, Alex Hall wrote: > >>> a = 5 > >>> isinstance(a, int) > True > >>> a is int > False > > What happened there? Don't these do the same thing? I thought I could use > them interchangeably? You're probably thinking of "is a", as in, "5 is an int", "'Hello W

Re: [Tutor] help with exercise 15 of zed shaw's LPTHW

2016-07-05 Thread Steven D'Aprano
Hi Heloisa, and welcome. Do you have a link to the code? Or better still, if it is short (say under fifty lines) can you copy it into an email and send it? On Wed, Jul 06, 2016 at 12:56:19AM +0100, loh...@tuta.io wrote: [...] > 1. the need to put script into an estipulation for argv (line 3) I