PEP 255: Simple Generators

Rainer Deyke root at rainerdeyke.com
Sat Jun 23 00:54:12 CEST 2001


"Andrew Dalke" <dalke at acm.org> wrote in message
news:9h0crt$rq6$1 at slb1.atl.mindspring.net...
> There isn't quite enough information to distinguish between at
> least some class definitions and function definitions without the
> use of a keyword.  Consider
>
> >>> class SuperTest:
> ... pass
> ...
> >>> def Test(SuperTest):
> ...     def __init__(self, spam):
> ...         self.spam = spam
> ...     def __str__(self):
> ...         return str(self.spam)
> >>> t = Test("eggs")
> >>> str(t)
> 'None'
> >>>

How about a new rule that requires the 'return' statement in a function?

# Class:
def c():
  def __init__(self, spam):
    self.spam = spam

# Function:
def f():
  def __init__(self, spam):
    self.spam = spam
  return

# Null generator:
def g():
  def __init__(self, spam):
    self.spam = spam
  return
  yield None


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list