cython hello world

Create cython hello.pyx script:

def say_hello_to(name):
    print("Hello %s!" % name)

Compile into shared object (credit to http://blog.perrygeo.net/2008/04/19/a-quick-cython-introduction/)
# this will create a hello.c file - the C source code to build a python extension
cython hello.pyx

# Compile the object file
gcc -c -fPIC -I/usr/include/python2.6/ hello.c

# Link it into a shared library
gcc -shared hello.o -o hello.so

Now you can import module hello in a regular python script:

from hello import say_hello_to
print(say_hello_to("Your_name"))
Advertisements
This entry was posted in Programming, Python and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s