Skip to content

Commit

Permalink
Moved the first code snippet of the extension_types.rst to the exampl…
Browse files Browse the repository at this point in the history
…es directory for testing.
  • Loading branch information
gabrieldemarmiesse committed Jun 17, 2018
1 parent f1815e7 commit 0333761
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 12 additions & 0 deletions docs/examples/userguide/extension_types/shrubbery.pyx
@@ -0,0 +1,12 @@
from __future__ import print_function

cdef class Shrubbery:
cdef int width, height

def __init__(self, w, h):
self.width = w
self.height = h

def describe(self):
print("This shrubbery is", self.width,
"by", self.height, "cubits.")
16 changes: 2 additions & 14 deletions docs/src/userguide/extension_types.rst
Expand Up @@ -12,21 +12,9 @@ Introduction
As well as creating normal user-defined classes with the Python class
statement, Cython also lets you create new built-in Python types, known as
extension types. You define an extension type using the :keyword:`cdef` class
statement. Here's an example::
statement. Here's an example:

from __future__ import print_function

cdef class Shrubbery:

cdef int width, height

def __init__(self, w, h):
self.width = w
self.height = h

def describe(self):
print("This shrubbery is", self.width,
"by", self.height, "cubits.")
.. literalinclude:: ../../examples/userguide/extension_types/shrubbery.pyx

As you can see, a Cython extension type definition looks a lot like a Python
class definition. Within it, you use the def statement to define methods that
Expand Down

0 comments on commit 0333761

Please sign in to comment.