Newbie tip: Prg speed from ~5 hrs to < 1 minute

Terry Byrne terrybyrne1963 at yahoo.com
Tue Apr 30 10:14:26 EDT 2002


Thanks, Geoff!

That's the clear sort of instruction I have a tough time finding elsewhere. 

Terry

Geoff Gerrietts <geoff at gerrietts.net> wrote in message news:<mailman.1020104212.2013.python-list at python.org>...
> The use of "pass" in the example doesn't actually do anything. I think
> what you're looking for is "continue". I can't explain the dramatic
> speedup you got out of adding them. It defies logic.
> 
> The "pass" keyword is a no-op. It's a placeholder. The idea is that
> you might want to do something like this:
> 
> class Spam:
>   pass
> 
> In this example, "pass" is a way to indicate that you don't want
> anything special -- your Spam class can use a default constructor, and
> needs no special methods. But you can't just write:
> 
> class Spam:
> 
> That's a syntax error. So "pass" allows you to say "do nothing
> special". This is also a way you can insert a virtual method:
> 
> class Spam:
>   def subclassed_operation(self):
>     pass
> 
> But "pass" isn't always the preferred approach. Lots of people have
> commented that better form might be:
> 
> class Spam:
>   def subclassed_operation(self):
>     """ this operation must be overridden by the subclass if it is to
>         do anything.
>     """
> 
> The doc string counts as a "statement" for the purposes of the
> compiler, making this valid syntax. Meanwhile, it provides explicit
> explanation of your intent.
> 
> Still others will prefer both: have a doc string AND a pass.
> 
> The "continue" keyword says "let's go back to the top of the loop and
> do the next item". The "break" keyword says "let's exit the loop right
> now, even if there's more work pending".
> 
> Those are your loop-control statements.
> 
> Luck,
> --G.



More information about the Python-list mailing list