The primary Python execution environment is commonly referred to as CPython, as it is written in
The primary Python execution environment is commonly referred to as CPython, as it is written in
C. Other major implementations use Java (Jython
C. Other major implementations use:
[#Jython]_), C# (IronPython [#IronPython]_) and Python
itself (PyPy [#PyPy]_).
:Java: Jython [#Jython]_
:C#: IronPython [#IronPython]_)
:Python itself: PyPy [#PyPy]_
Written in C, CPython has been
Written in C, CPython has been
conducive to wrapping many external libraries that interface through the C language. It has, however, remained non trivial to write the necessary glue code in
conducive to wrapping many external libraries that interface through the C language. It has, however, remained non trivial to write the necessary glue code in
...
@@ -83,6 +82,18 @@ Where Do I Get It?
...
@@ -83,6 +82,18 @@ Where Do I Get It?
Well.. at `cython.org <http://cython.org>`_.. of course!
Well.. at `cython.org <http://cython.org>`_.. of course!
How Do I Report a Bug?
======================
I Want To Make A Feature Request!
=================================
How Can I Contact You?
=======================
.. rubric:: Footnotes
.. rubric:: Footnotes
.. [#Jython] **Jython:** \J. Huginin, B. Warsaw, F. Bock, et al., Jython: Python for the Java platform, http://www.jython.org/
.. [#Jython] **Jython:** \J. Huginin, B. Warsaw, F. Bock, et al., Jython: Python for the Java platform, http://www.jython.org/
...
@@ -96,3 +107,13 @@ Well.. at `cython.org <http://cython.org>`_.. of course!
...
@@ -96,3 +107,13 @@ Well.. at `cython.org <http://cython.org>`_.. of course!
* The included code can itself contain other ``include`` statements.
* The included code can itself contain other ``include`` statements.
===========
====================
Data Typing
Declaring Data Types
===========
====================
.. contents::
.. note::
:local:
.. todo::
I think having paragraphs like this should be somewhere else which we can link to from here
..
I think having paragraphs like this should only be in the tutorial which
we can link to from here
As a dynamic language, Python encourages a programming style of considering classes and objects in terms of their methods and attributes, more than where they fit into the class hierarchy.
As a dynamic language, Python encourages a programming style of considering classes and objects in terms of their methods and attributes, more than where they fit into the class hierarchy.
...
@@ -185,8 +175,8 @@ The ``cdef`` statement is used to make C level declarations for:
...
@@ -185,8 +175,8 @@ The ``cdef`` statement is used to make C level declarations for:
tons_of_spam = 3
tons_of_spam = 3
Grouping
Grouping cdef Declarations
========
==========================
A series of declarations can grouped into a ``cdef`` block::
A series of declarations can grouped into a ``cdef`` block::
...
@@ -201,21 +191,124 @@ A series of declarations can grouped into a ``cdef`` block::
...
@@ -201,21 +191,124 @@ A series of declarations can grouped into a ``cdef`` block::
void f(Spam *s):
void f(Spam *s):
print s.tons, "Tons of spam"
print s.tons, "Tons of spam"
Parameters
Parameters
==========
==========
* All the different **function** types can be declared to have C data types.
* Both C and Python **function** types can be declared to have parameters C data types.
* Use normal C declaration syntax.
* Use normal C declaration syntax::
* **Python callable functions** can also be declared with C data types.
def spam(int i, char *s):
...
cdef int eggs(unsigned long l, float f):
...
* As these parameters are passed into a Python declared function, they are magically **converted** to the specified C type value.
* This holds true for only numeric and string types
.. todo::
The previous statement is still true ..??
* If no type is specified for a parameter or a return value, it is assumed to be a Python object
* The following takes two Python objects as parameters and returns a Python object::
cdef spamobjs(x, y):
...
* .. note::
This is different then C language behavior, where it is an int by default.
* Python object types have reference counting performed according to the standard Python C-API rules:
* Borrowed references are taken as parameters
* New references are returned
.. todo::
link or label here the one ref count caveat for numpy.
* The name ``object`` can be used to explicitly declare something as a Python Object.
* For sake of code clarity, it recomened to always use ``object`` explicitly in your code.
* This is also useful for cases where the name being declared would otherwise be taken for a type::
cdef foo(object int):
...
* As a return type::
cdef object foo(object int):
...
.. todo::
Do a see also here ..??
Automatic Type Conversion
=========================
* For basic numeric and string types, in most situations, when a Python object is used in the context of a C value and vice versa.
* The following table summarises the conversion possibilities: