Re: [Tutor] How to invoke different member-function according to different object?

2012-01-06 Thread Steven D'Aprano
daedae11 wrote: 2. I think it's a little tedious, but I don't know how to improve it. Welcome to programming! In the school books and example code, you see a nice, clean, fifteen line function and think that programming is easy. Then you try to write the program, and you start of with 15

Re: [Tutor] Subclassing Exceptions

2012-01-06 Thread Steven D'Aprano
Devin Jeanpierre wrote: Inheriting from SyntaxError doesn't work! When I create a new exception, I generally subclass from the built-in exception it most resembles, in case there was some reason to also catch it via an ancestor. But I'm not sure if that is really all that useful an idea in prac

Re: [Tutor] Subclassing Exceptions

2012-01-06 Thread Steven D'Aprano
Chris Fuller wrote: class Foo(SyntaxError): ... def __init__(self, a,b,c): ... self.args = (a,b,c) ... raise Foo(1,2,3) Traceback (most recent call last): File "", line 1, in __main__.Foo: None Inheriting from SyntaxError doesn't work! When I create a new exception, I generally sub

Re: [Tutor] Subclassing Exceptions

2012-01-06 Thread Devin Jeanpierre
> Inheriting from SyntaxError doesn't work! When I create a new exception, I > generally subclass from the built-in exception it most resembles, in case > there was some reason to also catch it via an ancestor. But I'm not sure if > that is really all that useful an idea in practice. How do you

[Tutor] How to invoke different member-function according to different object?

2012-01-06 Thread daedae11
I was asked to write a program to move files between ZIP(.zip) and TAR/GZIP(.tgz/.tar.gz) or TAR/BZIP2(.tbz/.tar.bz2) archive. my code is: import zipfile; import tarfile; import os; from os import path ; def showAllFiles(fileObj): if fileObj.filename.endswith("zip"): if isinstance

[Tutor] Subclassing Exceptions

2012-01-06 Thread Chris Fuller
I had an interesting experience today. Python 2.7.1 (r271:86832, Nov 28 2010, 19:31:37) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(Exception): ... def __init__(self, a,b,c): ... self.args = (a,b,c) ... >>> raise Foo(1,2,3) Traceb

Re: [Tutor] Making a Computer Guess My Number

2012-01-06 Thread Dave Angel
On 01/06/2012 03:05 PM, Garland W. Binns wrote: Hello, I have been experimenting with trying to rewrite the following script so that a computer tries to guess a number I'm thinking of: https://gist.github.com/1572067 I was thinking that basically I need to create a while loop, and somehow redefi

[Tutor] Making a Computer Guess My Number

2012-01-06 Thread Garland W. Binns
Hello, I have been experimenting with trying to rewrite the following script so that a computer tries to guess a number I'm thinking of: https://gist.github.com/1572067 I was thinking that basically I need to create a while loop, and somehow redefine the randrange depending on whether or not I pro

Re: [Tutor] Using Python for a client interactive map application

2012-01-06 Thread Lie Ryan
On 01/06/2012 04:16 AM, Alan Gauld wrote: That's a non trivial application. It sounds a lot like Google maps? If by map you meant real world maps, this task becomes pretty much trivial. It is fairly easy to embed Google Map in your own web app, and their API provides a lot for almost anything