Re: [Tutor] python2 vs python3 urllib
On 11-04-23 06:58 PM, pierre dagenais wrote: The following code works as expected with python version 2.6.5, but with version 3.1.2 I get the following error: pierre:/MyCode/mesProjets$ py3 test.py Traceback (most recent call last): File test.py, line 3, in module sock = urllib.urlopen(http://diveintopython.org/;) AttributeError: 'module' object has no attribute 'urlopen' The code: #example 8.5 of diveintopython.org/ import urllib sock = urllib.urlopen(http://diveintopython.org/;) htmlSource = sock.read() sock.close() print (htmlSource) What is the proper syntax in version 3? Thank you, Your help is much appreciated. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Thank you everybody, The short answer was of course: import urllib.request instead of : import urllib I realize I'm still confused about packages, libraries, modules, classes, etc... Right now they're all more or less the same to me. I've got some reading to do. Thanks again, Pierre ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Virtualenv Error
Malcolm Newsome malcolm.news...@gmail.com wrote I installed virtualenv and am getting this error when trying to create one. I'm running Windows 7. Can anyone help?? I've no idea what virtuialenv is or does but it doesn't sound like a Python beginners questuion You might get more success asking on the general python mailing list/nesgroup comp.lang.python. Or even better on a virtualenv list or forum is such a thing exists. Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Unbound Method Error
Because of the limited Python 3 support, I've decided to attempt to push my over 600 lines of code back to Python 2.6. Surprisingly, it worked well for the most part, except for the following section of code. crash = pygame.sprite.spritecollide(playerCar, computerSprites, False) if crash: for BlueCarSprite in crash: redracersprites26.BlueCarSprite.collide(BlueCarSprite, playerCar) for GreenCarSprite in crash: redracersprites26.GreenCarSprite.collide(GreenCarSprite, playerCar) for TruckSprite in crash: redracersprites26.TruckSprite.collide(TruckSprite, playerCar) This is a perfectly good piece of code in Python 3.1.3 which checks to see if a user controlled sprite collides with one or more computer controlled sprites, then passes the data off to the proper class method to handle the details. In Python 2.6.6, this section of code returns the following error TypeError: unbound method collide() must be called with BlueCarSprite instance as first argument (got GreenCarSprite instance instead) I have several questions as to what exactly is going on and what I should do, if you have any sort of answer to any of these questions, please respond. 1) What exactly is an unbound method error? I have been programming (in other languages) for several years on and off and have never heard of something like this. 2) What changes between 3.1.3 and 2.6.6 that makes this section of code not work? My best guess is that I'm missing something that lets the computer know that BlueCarSprite is an object type, but even if that's true, I wouldn't know what to do to fix it. 3) What would be a legit fix to my code to make it run? Sure, I guess I could write a Collide class and use that rather than my collide method, or perhaps a class that could act as a middle man between bits of code that I know work, but I know that there has to be a better way to fix this. Thank you to any and all who take the time to read this message, and especially to those who respond with any sort of feedback Greg ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unbound Method Error
Greg Nielsen wrote: In Python 2.6.6, this section of code returns the following error TypeError: unbound method collide() must be called with BlueCarSprite instance as first argument (got GreenCarSprite instance instead) Please copy and paste the actual traceback, as that will show the *actual* line of code (and not just this section). 1) What exactly is an unbound method error? I have been programming (in other languages) for several years on and off and have never heard of something like this. When you retrieve an attribute from an instance: instance.name Python looks up name on the instance, then class, then any parent classes, etc. The same mechanism is used for methods: the method object just happens to be callable. When you retrieve instance.method, you get back a method-wrapper object which wraps the function you defined in the class. The method-wrapper ensures that the special self argument is supplied, so that this syntax: instance.method(x, y, z) calls the actual function object like this: type(instance).method(instance, x, y, z) Some people find it hard to wrap their head around this, but remember that you have defined an ordinary function inside the class, using the same def key word that gets used for making other functions. You write a function, and the class wraps it in code to make it a method. Now, when you call instance.method, the object you get back is a bound method, so-called because it is bound to an instance and can supply the self argument. But when you call the method on the class object instead: Class.method you get an *unbound* method, which is still a wrapper around the actual function you defined. Remember the parameter list you defined in the function? It starts with self. If you call it via the instance, you get a bound method and self if automatically provided. But if you call it from the class, there is no instance supplied and you have to supply it by hand. You can easily experiment with this using built-ins such as str: spam.upper built-in method upper of str object at 0xb7f2d780 spam.upper() # self is set to spam 'SPAM' str.upper method 'upper' of 'str' objects str.upper() Traceback (most recent call last): File stdin, line 1, in module TypeError: descriptor 'upper' of 'str' object needs an argument str.upper(spam) 'SPAM' Some of the implementation details (such as error messages) may differ between methods in Python classes and methods in built-in types, but the broad details are the same. 2) What changes between 3.1.3 and 2.6.6 that makes this section of code not work? My best guess is that I'm missing something that lets the computer know that BlueCarSprite is an object type, but even if that's true, I wouldn't know what to do to fix it. I suspect that you're running into a small semantic difference between Python 2 and 3. In Python 2, method objects know what their type is, and they enforce that the self argument has the same type. In Python 3, unbound methods are gone, and instance you get an ordinary function. This ordinary function has no clue about what class it is attached to, and so it can't enforce that the self parameter has the right class. You can pass anything that works. 3) What would be a legit fix to my code to make it run? Sure, I guess I could write a Collide class and use that rather than my collide method, or perhaps a class that could act as a middle man between bits of code that I know work, but I know that there has to be a better way to fix this. Perhaps you can make GreenCarSprite a subclass of BlueCarSprite, or both Blue* and Green* to be subclasses of a CarSprite class that owns all the methods. But without knowing more about your code, it's hard to say exactly. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unbound Method Error
First and foremost, thank you Steven for your quick and well written response. It means a lot to me that you took the time out of your day to answer my question, and it has really helped me better understand what it going on. So the full trace back for my error is as follows: Traceback (most recent call last): File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 19, in module main() File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 16, in main redracerstates26.game(startLives) File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracerstates26.py, line 87, in game redracersprites26.BlueCarSprite.collide(BlueCarSprite, playerCar) TypeError: unbound method collide() must be called with BlueCarSprite instance as first argument (got GreenCarSprite instance instead) After reading through your explanation of unbound methods (and wrapping my head around the concept), I came up with a quick fix that lead to a new issue in my code. Here is what I think should work: crash = pygame.sprite.spritecollide(playerCar, computerSprites, False) if crash: for BlueCarSprite in crash: redracersprites26.BlueCarSprite.collide(crash, playerCar) for GreenCarSprite in crash: redracersprites26.GreenCarSprite.collide(crash, playerCar) for TruckSprite in crash: redracersprites26.TruckSprite.collide(crash, playerCar) However, the spritecollide method returns a list, which my collide method isn't expecting. The list should only contain the name of the sprite the player hit. In Python 3, the method would just pull the variable out of the list and work with it, but in Python 2, it's not expecting a list, causing an error similar to the one seen previously: Traceback (most recent call last): File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 19, in module main() File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 16, in main redracerstates26.game(startLives) File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracerstates26.py, line 87, in game redracersprites26.BlueCarSprite.collide(crash, playerCar) TypeError: unbound method collide() must be called with BlueCarSprite instance as first argument (got list instance instead) So what really has to happen now (I think) is that the list needs to be unpacked into just a simple variable containing the name of the sprite in question. This way the method receives the name of the instance (self) in the way it was expecting to receive it. In your opinion, should I unpacked the list before passing the data into the method, or attempt to define self as a list? Is the latter even possible? I would think it would have to be because otherwise Python could pick a variable type which you don't want or aren't expecting it to pick and need to force it to take a certain type of input. And thank you for pointing out the fact I could just make a CarSprite class and have subclasses (basically just a different sprite image) work with the details. You just removed over 150 lines of redundant code from my program. And once again, thank you Steven for taking the time to help me better understand the whole unbound method concept. Greg ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] voluntary work
someboy have some project where can take a very noob and with very little knowledgement of python in the arm where i can work voluntary of course ? the thing is i want learn i read a bit and do some exercises but i am the kind of ppl that need saw the path that will walk so need a route and a little of guide to keep going , thanks pd: i ask the same question at #python in freenode that somebody recommend me the book http://learnpythonthehardway.org/static/LearnPythonTheHardWay.pdf and i check it it righ now. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Assistance
while numberOfGrades != gradesEntered: grade = int(raw_input(Please enter the grade: )) gradesEntered += 1 score =+ grade Note that += and =+ do different things. I suspect this last line is not doing what you think. Details like this are very important in programming, especially since both forms are valid code, they just do different things! Could you please expand on that? From playing around on the shell it looks like 'B =+ 2 ' always sets B to 2. At first, I thought it was taking it as 'B=None+2' but that gave me the error TypeError: unsupported operand type(s) for +: 'NoneType' and 'int' So what is actually going on behind the scenes? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unbound Method Error
Disclaimer: I have no knowledge of PyGame. I think your original is a lack of checking types. You are calling BlueCar/GreenCar/Truck.collide regardless of the car type. If you pass a TruckSprite to BlueCarSprite.collide it makes sense (without knowledge of PyGame) that it would fail because it expects a BlueCarSprite not a TruckSprite. You do: crash = pygame.sprite.spritecollide(playerCar, computerSprites, False) if crash: for BlueCarSprite in crash: # This loops through crash redracersprites26.BlueCarSprite.collide(crash, playerCar) for GreenCarSprite in crash: # This loops through crash again redracersprites26.GreenCarSprite.collide(crash, playerCar) for TruckSprite in crash: # This loops through crash for the third time redracersprites26.TruckSprite.collide(crash, playerCar) There are two other problems with this: 1) this is sending the entire list of collisions to each of these functions. 2) The way you are looping seems odd to me. I would think you want something more like the following (UNTESTED): crash = pygame.sprite.spritecollide(playerCar, computerSprites, False) if crash: for car in crash: if isinstance(car, BlueCar): redracersprices26.BlueCarSprite.collide(car, playerCar) if isinstance(car, GreenCar): redracersprices26.GreenCarSprite.collide(car, playerCar) if isinstance(car, TruckCar): redracersprices26.TruckCarSprite.collide(car, playerCar) If you really want to call all 3 collide statements, then just remove the 'if isinstance(car, \w*):' line and it will call the collide for each. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 From: tutor-bounces+ramit.prasad=jpmchase@python.org [mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of Greg Nielsen Sent: Monday, April 25, 2011 4:37 AM To: Steven D'Aprano Cc: tutor@python.org Subject: Re: [Tutor] Unbound Method Error First and foremost, thank you Steven for your quick and well written response. It means a lot to me that you took the time out of your day to answer my question, and it has really helped me better understand what it going on. So the full trace back for my error is as follows: Traceback (most recent call last): File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 19, in module main() File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 16, in main redracerstates26.game(startLives) File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracerstates26.py, line 87, in game redracersprites26.BlueCarSprite.collide(BlueCarSprite, playerCar) TypeError: unbound method collide() must be called with BlueCarSprite instance as first argument (got GreenCarSprite instance instead) After reading through your explanation of unbound methods (and wrapping my head around the concept), I came up with a quick fix that lead to a new issue in my code. Here is what I think should work: crash = pygame.sprite.spritecollide(playerCar, computerSprites, False) if crash: for BlueCarSprite in crash: redracersprites26.BlueCarSprite.collide(crash, playerCar) for GreenCarSprite in crash: redracersprites26.GreenCarSprite.collide(crash, playerCar) for TruckSprite in crash: redracersprites26.TruckSprite.collide(crash, playerCar) However, the spritecollide method returns a list, which my collide method isn't expecting. The list should only contain the name of the sprite the player hit. In Python 3, the method would just pull the variable out of the list and work with it, but in Python 2, it's not expecting a list, causing an error similar to the one seen previously: Traceback (most recent call last): File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 19, in module main() File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 16, in main redracerstates26.game(startLives) File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracerstates26.py, line 87, in game redracersprites26.BlueCarSprite.collide(crash, playerCar) TypeError: unbound method collide() must be called with BlueCarSprite instance as first argument (got list instance instead) So what really has to happen now (I think) is that the list needs to be unpacked into just a simple variable containing the name of the sprite in question. This way the method receives the name of the instance (self) in the way it was expecting to receive it. In your opinion, should I unpacked the list before passing the data into the method, or attempt to define self as a list? Is the latter even possible? I would think it would have to be because
Re: [Tutor] Assistance
On Mon, Apr 25, 2011 at 9:59 AM, Prasad, Ramit ramit.pra...@jpmchase.comwrote: while numberOfGrades != gradesEntered: grade = int(raw_input(Please enter the grade: )) gradesEntered += 1 score =+ grade Note that += and =+ do different things. I suspect this last line is not doing what you think. Details like this are very important in programming, especially since both forms are valid code, they just do different things! Could you please expand on that? From playing around on the shell it looks like 'B =+ 2 ' always sets B to 2. At first, I thought it was taking it as 'B=None+2' but that gave me the error TypeError: unsupported operand type(s) for +: 'NoneType' and 'int' So what is actually going on behind the scenes? Ramit += is a single operator that is equivalent to typing b = b + 2 =+ is two operators put together: b+=2 is equivalent to b += 2 is equivalent to b = b + 2 b=+2 is equivalent to b = +2 is equivalent to b = 2 b = + 2 is legal syntax, while b + = 2 is not. HTH, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] voluntary work
Edgar Almonte samud...@gmail.com wrote is i want learn i read a bit and do some exercises but i am the kind of ppl that need saw the path that will walk so need a route and a little of guide to keep going , Have you looked at the python web site? There is a whole section dedicated to tutorials for people who have never programmed before. Take a look at a few and choose the one you like - ie the one that aseems to make most sense to you.. HTH, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] voluntary work
Thanks , but i still are looking for some small project to get work that let me learn in a more interesting way. i not that kind of person that can start app from zero so is hard for me learn new things without some kind of goal. thanks again. On Mon, Apr 25, 2011 at 1:33 PM, Alan Gauld alan.ga...@btinternet.com wrote: Edgar Almonte samud...@gmail.com wrote is i want learn i read a bit and do some exercises but i am the kind of ppl that need saw the path that will walk so need a route and a little of guide to keep going , Have you looked at the python web site? There is a whole section dedicated to tutorials for people who have never programmed before. Take a look at a few and choose the one you like - ie the one that aseems to make most sense to you.. HTH, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] voluntary work
Learn Python the Hard Way is pretty cool. I am always looking for books that lay it out well. Thanks for mentioning it, and good luck with your studies. I find that having a project that is a little beyond me helps me get better at coding. -Wolf On Mon, Apr 25, 2011 at 1:33 PM, Alan Gauld alan.ga...@btinternet.comwrote: Edgar Almonte samud...@gmail.com wrote is i want learn i read a bit and do some exercises but i am the kind of ppl that need saw the path that will walk so need a route and a little of guide to keep going , Have you looked at the python web site? There is a whole section dedicated to tutorials for people who have never programmed before. Take a look at a few and choose the one you like - ie the one that aseems to make most sense to you.. HTH, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- This Apt Has Super Cow Powers - http://sourcefreedom.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] voluntary work
I recommend you visit www.pythonchallenge.com On 25/04/11 20:42, Wolf Halton wrote: Learn Python the Hard Way is pretty cool. I am always looking for books that lay it out well. Thanks for mentioning it, and good luck with your studies. I find that having a project that is a little beyond me helps me get better at coding. -Wolf On Mon, Apr 25, 2011 at 1:33 PM, Alan Gauld alan.ga...@btinternet.com mailto:alan.ga...@btinternet.com wrote: Edgar Almonte samud...@gmail.com mailto:samud...@gmail.com wrote is i want learn i read a bit and do some exercises but i am the kind of ppl that need saw the path that will walk so need a route and a little of guide to keep going , Have you looked at the python web site? There is a whole section dedicated to tutorials for people who have never programmed before. Take a look at a few and choose the one you like - ie the one that aseems to make most sense to you.. HTH, ___ Tutor maillist - Tutor@python.org mailto:Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- This Apt Has Super Cow Powers - http://sourcefreedom.com ___ Tutor maillist -Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unbound Method Error
Ramit, First, thank you for your input and insight into my problem, I believe that the code you came up with should not only be more efficient, but also clear up the last of my issues. I just have a quick question on the isinstance command you called. How exactly do I get the code to recognize it as a class I wrote sitting in an imported library file? I would guess that it would look sort of like this: if crash: for car in crash: if isinstance(car, redracersprites26.BlueCarSprite()): redracersprites26.BlueCarSprite.collide(car, playerCar) However, worded as it the follow error and call back happens: Traceback (most recent call last): File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 19, in module main() File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 16, in main redracerstates26.game(startLives) File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracerstates26.py, line 87, in game if isinstance(car, redracersprites26.BlueCarSprite()): TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types I must be using the wrong syntax in the second argument. I think I should be able to find the documentation for this (extremely cool) method you showed me, but if you know the proper way to cite my object, could you send me what you think will work. This way I can have something to double check my work against if I don't get it right first time round. Thank you again for your time and assistance Ramit. Greg ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unbound Method Error
Hi Greg, You must use the class definition not an instance/object of it. If the class is called CarClass from some_lib_a.sub_lib_b import CarClass [...] isinstance(car, CarClass) OR import some_lib_a [...] isinstance(car, some_lib_a.sub_lib_b.CarClass) The following does NOT work: isinstance(car, CarClass()) if you want to check multiple classes use isinstance(car, (Class1, Class2)) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 From: Greg Nielsen [mailto:gollumgreg407...@gmail.com] Sent: Monday, April 25, 2011 3:19 PM To: Prasad, Ramit Cc: Steven D'Aprano; tutor@python.org Subject: Re: [Tutor] Unbound Method Error Ramit, First, thank you for your input and insight into my problem, I believe that the code you came up with should not only be more efficient, but also clear up the last of my issues. I just have a quick question on the isinstance command you called. How exactly do I get the code to recognize it as a class I wrote sitting in an imported library file? I would guess that it would look sort of like this: if crash: for car in crash: if isinstance(car, redracersprites26.BlueCarSprite()): redracersprites26.BlueCarSprite.collide(car, playerCar) However, worded as it the follow error and call back happens: Traceback (most recent call last): File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 19, in module main() File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracer26.py, line 16, in main redracerstates26.game(startLives) File C:\Users\Greg\Documents\NetBeansProjects\Red Racer 26\src\redracerstates26.py, line 87, in game if isinstance(car, redracersprites26.BlueCarSprite()): TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types I must be using the wrong syntax in the second argument. I think I should be able to find the documentation for this (extremely cool) method you showed me, but if you know the proper way to cite my object, could you send me what you think will work. This way I can have something to double check my work against if I don't get it right first time round. Thank you again for your time and assistance Ramit. Greg This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities.___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] voluntary work :p:
On Mon, 25 Apr 2011 15:09:02 -0400 Rafael Durán Castañeda rafadurancastan...@gmail.com wrote: I recommend you visit www.pythonchallenge.comhttp://www.pythonchallenge.com On 25/04/11 20:42, Wolf Halton wrote: Learn Python the Hard Way is pretty cool. I am always looking for books that lay it out well. Thanks for mentioning it, and good luck with your studies. I find that having a project that is a little beyond me helps me get better at coding. -Wolf On Mon, Apr 25, 2011 at 1:33 PM, Alan Gauld alan.ga...@btinternet.commailto:alan.ga...@btinternet.com wrote: Edgar Almonte samud...@gmail.commailto:samud...@gmail.com wrote is i want learn i read a bit and do some exercises but i am the kind of ppl that need saw the path that will walk so need a route and a little of guide to keep going , Have you looked at the python web site? There is a whole section dedicated to tutorials for people who have never programmed before. Take a look at a few and choose the one you like - ie the one that aseems to make most sense to you.. HTH, I second the recommendation to try out Python Challenge - outstanding way to learn (at least for me). Another option is to visit Sourceforge.net and look for python projects still in development. Open source pojects seem to always need bug finders and smashers as well as beta testers and I suspect most any of them would appreciate free help! tom ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] voluntary work :p:
Thanks all for the answer, python challenge is cool but i think need more python and programing level that i current have, ( i ended looking for the answer at google ) i will continue reading Learn Python the Hard Way 2011/4/25 Thomas C. Hicks para...@pobox.com: On Mon, 25 Apr 2011 15:09:02 -0400 Rafael Durán Castañeda rafadurancastan...@gmail.com wrote: I recommend you visit www.pythonchallenge.comhttp://www.pythonchallenge.com On 25/04/11 20:42, Wolf Halton wrote: Learn Python the Hard Way is pretty cool. I am always looking for books that lay it out well. Thanks for mentioning it, and good luck with your studies. I find that having a project that is a little beyond me helps me get better at coding. -Wolf On Mon, Apr 25, 2011 at 1:33 PM, Alan Gauld alan.ga...@btinternet.commailto:alan.ga...@btinternet.com wrote: Edgar Almonte samud...@gmail.commailto:samud...@gmail.com wrote is i want learn i read a bit and do some exercises but i am the kind of ppl that need saw the path that will walk so need a route and a little of guide to keep going , Have you looked at the python web site? There is a whole section dedicated to tutorials for people who have never programmed before. Take a look at a few and choose the one you like - ie the one that aseems to make most sense to you.. HTH, I second the recommendation to try out Python Challenge - outstanding way to learn (at least for me). Another option is to visit Sourceforge.net and look for python projects still in development. Open source pojects seem to always need bug finders and smashers as well as beta testers and I suspect most any of them would appreciate free help! tom ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] after(), how do I use it?
Hello, I asked for help in another location and it solved my problem, but the only problem is I don't fully understand the after function. Here is part of the code that was given to me. def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget(text) t += message[0] self.label.config(text=t) if len(message) 1: self.after(500, self.print_label_slowly, message[1:]) I understand it, and the gist of how it works, but the self.after... I can not find any documentation on it (because after is such a common word), so can you guys tell me how it works. Is this a built in function (didn't see it on the built in function list)? Does it always take 3 arguements? Is this a user made function and I'm just overlooking where it was defined at? What is it about you... that intrigues me so? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] after(), how do I use it?
On 26/04/11 01:36, michael scott wrote: Hello, I asked for help in another location and it solved my problem, but the only problem is I don't fully understand the after function. Here is part of the code that was given to me. def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget(text) t += message[0] self.label.config(text=t) if len(message) 1: self.after(500, self.print_label_slowly, message[1:]) I understand it, and the gist of how it works, but the self.after... I can not find any documentation on it (because after is such a common word), so can you guys tell me how it works. Is this a built in function (didn't see it on the built in function list)? Does it always take 3 arguements? Is this a user made function and I'm just overlooking where it was defined at? The function you have shown there appears to be a class method. self.after means you are calling another method of the same function that print_label_slowly is a part of. Do you have the rest of the code? If you're still confused post it and hopefully we can clear it up for you. HTH, Adam. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unbound Method Error
Greg Nielsen wrote: if isinstance(car, redracersprites26.BlueCarSprite()): TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types Don't instantiate the class. Instead of redracersprites26.BlueCarSprite() # makes a new instance just refer to the class object without calling it: redracersprites26.BlueCarSprite -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] after(), how do I use it?
Here is the code in its entirety, it works although I don't see after() defined, so I assumed it was a built in function. I can just copy and paste parts of this code into my project, so its not imperative that I understand, but I prefer to use the weapons I've been given. So I hope that you guys can understand it a bit better after I post this. import Tkinter as tk class App(tk.Tk): def __init__(self,*args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.label = tk.Label(self, text=, width=20, anchor=w) self.label.pack(side=top,fill=both,expand=True) self.print_label_slowly(Hello, world!) def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget(text) t += message[0] self.label.config(text=t) if len(message) 1: self.after(500, self.print_label_slowly, message[1:]) app = App() app.mainloop() What is it about you... that intrigues me so? From: Adam Bark adam.jt...@gmail.com To: tutor@python.org Sent: Mon, April 25, 2011 8:50:16 PM Subject: Re: [Tutor] after(), how do I use it? On 26/04/11 01:36, michael scott wrote: Hello, I asked for help in another location and it solved my problem, but the only problem is I don't fully understand the after function. Here is part of the code that was given to me. def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget(text) t += message[0] self.label.config(text=t) if len(message) 1: self.after(500, self.print_label_slowly, message[1:]) I understand it, and the gist of how it works, but the self.after... I can not find any documentation on it (because after is such a common word), so can you guys tell me how it works. Is this a built in function (didn't see it on the built in function list)? Does it always take 3 arguements? Is this a user made function and I'm just overlooking where it was defined at? The function you have shown there appears to be a class method. self.after means you are calling another method of the same function that print_label_slowly is a part of. Do you have the rest of the code? If you're still confused post it and hopefully we can clear it up for you. HTH, Adam. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] after(), how do I use it?
On Mon, Apr 25, 2011 at 8:02 PM, michael scott jigenbak...@yahoo.comwrote: Here is the code in its entirety, it works although I don't see after() defined, so I assumed it was a built in function. I can just copy and paste parts of this code into my project, so its not imperative that I understand, but I prefer to use the weapons I've been given. So I hope that you guys can understand it a bit better after I post this. That it is indeed. Do you understand classes and subclassing in Python? App is a subclass of tk.Tk. If you have done any of your own programming in Tkinter, you should know that Tk is the main class in Tkinter. If you do a Google search for Tkinter after, the top two results will answer your question: http://www.google.com/search?sourceid=chromeie=UTF-8q=tkinter+after HTH, Wayne import Tkinter as tk class App(tk.Tk): def __init__(self,*args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.label = tk.Label(self, text=, width=20, anchor=w) self.label.pack(side=top,fill=both,expand=True) self.print_label_slowly(Hello, world!) def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget(text) t += message[0] self.label.config(text=t) if len(message) 1: self.after(500, self.print_label_slowly, message[1:]) app = App() app.mainloop() What is it about you... that intrigues me so? -- *From:* Adam Bark adam.jt...@gmail.com *To:* tutor@python.org *Sent:* Mon, April 25, 2011 8:50:16 PM *Subject:* Re: [Tutor] after(), how do I use it? On 26/04/11 01:36, michael scott wrote: Hello, I asked for help in another location and it solved my problem, but the only problem is I don't fully understand the after function. Here is part of the code that was given to me. def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget(text) t += message[0] self.label.config(text=t) if len(message) 1: self.after(500, self.print_label_slowly, message[1:]) I understand it, and the gist of how it works, but the self.after... I can not find any documentation on it (because after is such a common word), so can you guys tell me how it works. Is this a built in function (didn't see it on the built in function list)? Does it always take 3 arguements? Is this a user made function and I'm just overlooking where it was defined at? The function you have shown there appears to be a class method. self.after means you are calling another method of the same function that print_label_slowly is a part of. Do you have the rest of the code? If you're still confused post it and hopefully we can clear it up for you. HTH, Adam. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] after(), how do I use it?
after(delay_ms, callback=None, *args) [#] Registers an alarm callback that is called after a given time. This method registers a callback function that will be called after a given number of milliseconds. Tkinter only guarantees that the callback will not be called earlier than that; if the system is busy, the actual delay may be much longer. The callback is only called once for each call to this method. To keep calling the callback, you need to reregister the callback inside itself: class App: def __init__(self, master): self.master = master self.poll() # start polling def poll(self): ... do something ... self.master.after(100, self.poll) after_cancel to cancel the callback. On Mon, Apr 25, 2011 at 9:15 PM, Wayne Werner waynejwer...@gmail.com wrote: On Mon, Apr 25, 2011 at 8:02 PM, michael scott jigenbak...@yahoo.com wrote: Here is the code in its entirety, it works although I don't see after() defined, so I assumed it was a built in function. I can just copy and paste parts of this code into my project, so its not imperative that I understand, but I prefer to use the weapons I've been given. So I hope that you guys can understand it a bit better after I post this. That it is indeed. Do you understand classes and subclassing in Python? App is a subclass of tk.Tk. If you have done any of your own programming in Tkinter, you should know that Tk is the main class in Tkinter. If you do a Google search for Tkinter after, the top two results will answer your question: http://www.google.com/search?sourceid=chromeie=UTF-8q=tkinter+after HTH, Wayne import Tkinter as tk class App(tk.Tk): def __init__(self,*args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.label = tk.Label(self, text=, width=20, anchor=w) self.label.pack(side=top,fill=both,expand=True) self.print_label_slowly(Hello, world!) def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget(text) t += message[0] self.label.config(text=t) if len(message) 1: self.after(500, self.print_label_slowly, message[1:]) app = App() app.mainloop() What is it about you... that intrigues me so? From: Adam Bark adam.jt...@gmail.com To: tutor@python.org Sent: Mon, April 25, 2011 8:50:16 PM Subject: Re: [Tutor] after(), how do I use it? On 26/04/11 01:36, michael scott wrote: Hello, I asked for help in another location and it solved my problem, but the only problem is I don't fully understand the after function. Here is part of the code that was given to me. def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget(text) t += message[0] self.label.config(text=t) if len(message) 1: self.after(500, self.print_label_slowly, message[1:]) I understand it, and the gist of how it works, but the self.after... I can not find any documentation on it (because after is such a common word), so can you guys tell me how it works. Is this a built in function (didn't see it on the built in function list)? Does it always take 3 arguements? Is this a user made function and I'm just overlooking where it was defined at? The function you have shown there appears to be a class method. self.after means you are calling another method of the same function that print_label_slowly is a part of. Do you have the rest of the code? If you're still confused post it and hopefully we can clear it up for you. HTH, Adam. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] after(), how do I use it?
Now I understand what I misunderstood. Well he imported Tkinter as tk, so I thought if it belonged to Tkinter it would be tk.after(), but the after was attached to the app, so it was in actuality app.after() . app inherits from the tk class (taking with it all its methods), so its a built in function of tkinter. I read the whole thread of the first google response, but I still wasn't sure if it was a Tkinter function or a python function. I searched the actual python documentation quite extensively, but briefly glanced at the tkinter effbot page, after not seeing it I came here. I was just looking for the documentation on after(). But yea, this is what I needed id = w.after(time, callback) So I know it takes 2 arguments, and I know to use it recursively in my problem, so now I understand enough about this function to put it to good use :) Thank you. What is it about you... that intrigues me so? From: Wayne Werner waynejwer...@gmail.com To: michael scott jigenbak...@yahoo.com Cc: tutor@python.org Sent: Mon, April 25, 2011 9:15:10 PM Subject: Re: [Tutor] after(), how do I use it? On Mon, Apr 25, 2011 at 8:02 PM, michael scott jigenbak...@yahoo.com wrote: Here is the code in its entirety, it works although I don't see after() defined, so I assumed it was a built in function. I can just copy and paste parts of this code into my project, so its not imperative that I understand, but I prefer to use the weapons I've been given. So I hope that you guys can understand it a bit better after I post this. That it is indeed. Do you understand classes and subclassing in Python? App is a subclass of tk.Tk. If you have done any of your own programming in Tkinter, you should know that Tk is the main class in Tkinter. If you do a Google search for Tkinter after, the top two results will answer your question: http://www.google.com/search?sourceid=chromeie=UTF-8q=tkinter+after HTH, Wayne import Tkinter as tk class App(tk.Tk): def __init__(self,*args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.label = tk.Label(self, text=, width=20, anchor=w) self.label.pack(side=top,fill=both,expand=True) self.print_label_slowly(Hello, world!) def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget(text) t += message[0] self.label.config(text=t) if len(message) 1: self.after(500, self.print_label_slowly, message[1:]) app = App() app.mainloop() What is it about you... that intrigues me so? From: Adam Bark adam.jt...@gmail.com To: tutor@python.org Sent: Mon, April 25, 2011 8:50:16 PM Subject: Re: [Tutor] after(), how do I use it? On 26/04/11 01:36, michael scott wrote: Hello, I asked for help in another location and it solved my problem, but the only problem is I don't fully understand the after function. Here is part of the code that was given to me. def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget(text) t += message[0] self.label.config(text=t) if len(message) 1: self.after(500, self.print_label_slowly, message[1:]) I understand it, and the gist of how it works, but the self.after... I can not find any documentation on it (because after is such a common word), so can you guys tell me how it works. Is this a built in function (didn't see it on the built in function list)? Does it always take 3 arguements? Is this a user made function and I'm just overlooking where it was defined at? The function you have shown there appears to be a class method. self.after means you are calling another method of the same function that print_label_slowly is a part of. Do you have the rest of the code? If you're still confused post it and hopefully we can clear it up for you. HTH, Adam. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] after(), how do I use it?
On Mon, Apr 25, 2011 at 8:34 PM, michael scott jigenbak...@yahoo.comwrote: So I know it takes 2 arguments, and I know to use it recursively in my problem, so now I understand enough about this function to put it to good use :) Thank you. Technically speaking it's not a recursive function call, it registers itself as a callback with the Tkinter mainloop. For more about recursion: http://www.google.com/search?sourceid=chromeie=UTF-8q=recursion HTH, Wayne http://www.google.com/search?sourceid=chromeie=UTF-8q=recursion ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unbound Method Error
And it works! Thank you once again to both Steven and Ramit for your peerless insight into the workings of Python and for taking time out of you day to help me work my code back to Python 2. I have learned much by talking with both of you over the last day or so. Greg ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] voluntary work :p:
I didn't get anything out of pythonchallenge. All seems static. Do you need flash or something to make the magic happen? On Mon, Apr 25, 2011 at 7:29 PM, Edgar Almonte samud...@gmail.com wrote: Thanks all for the answer, python challenge is cool but i think need more python and programing level that i current have, ( i ended looking for the answer at google ) i will continue reading Learn Python the Hard Way 2011/4/25 Thomas C. Hicks para...@pobox.com: On Mon, 25 Apr 2011 15:09:02 -0400 Rafael Durán Castañeda rafadurancastan...@gmail.com wrote: I recommend you visit www.pythonchallenge.comhttp://www.pythonchallenge.com On 25/04/11 20:42, Wolf Halton wrote: Learn Python the Hard Way is pretty cool. I am always looking for books that lay it out well. Thanks for mentioning it, and good luck with your studies. I find that having a project that is a little beyond me helps me get better at coding. -Wolf On Mon, Apr 25, 2011 at 1:33 PM, Alan Gauld alan.ga...@btinternet.commailto:alan.ga...@btinternet.com wrote: Edgar Almonte samud...@gmail.commailto:samud...@gmail.com wrote is i want learn i read a bit and do some exercises but i am the kind of ppl that need saw the path that will walk so need a route and a little of guide to keep going , Have you looked at the python web site? There is a whole section dedicated to tutorials for people who have never programmed before. Take a look at a few and choose the one you like - ie the one that aseems to make most sense to you.. HTH, I second the recommendation to try out Python Challenge - outstanding way to learn (at least for me). Another option is to visit Sourceforge.net and look for python projects still in development. Open source pojects seem to always need bug finders and smashers as well as beta testers and I suspect most any of them would appreciate free help! tom ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- This Apt Has Super Cow Powers - http://sourcefreedom.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] voluntary work :p:
On 4/25/2011 11:59 PM, Wolf Halton wrote: I didn't get anything out of pythonchallenge. Nothing? No web pages? All seems static. Now you say All instead of nothing. Did you get more than 1 web page? Do you need flash or something to make the magic happen? What are you expecting? What magic? Did you see an image of a monitor with 2 to the 38 on it? Did you see Hint: try to change the URL address.? Did you try that? -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor