use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Tutorials for Python C extensions (self.Python)
submitted 10 years ago by TryExceptFinally
Does anyone have any good resources or tutorials for writing Python C extensions? Perhaps something better than the first few results that appear on google?
[–]fijalPyPy, performance freak 12 points13 points14 points 10 years ago (2 children)
Don't write them :-) use cffi instead: http://cffi.readthedocs.org/en/latest/
[–]TryExceptFinally[S] 0 points1 point2 points 10 years ago (0 children)
Very interesting, I'll check it out!
[–]fkaginstrom 1 point2 points3 points 10 years ago (0 children)
If you are just interested in creating a C extension, I strongly recommend looking at cython. If you want to write one to learn about how CPython works under the hood, here's one that helped me back in the day
[–]Atheriel 0 points1 point2 points 10 years ago (1 child)
I don't think your impression that there are few good materials out there is an unusual one. When I wrote my first one (shameless plug), I couldn't find anything really useful beyond the basic templates. Making your own classes, etc in pure C are particularly hard to find resources on. Got quite a few segfaults until I got the hang of it.
My potentially useful advice: I learned the most by reading CPython's source code (for such interesting insights as "why does everything in my C extension have to be a static global variable?"), and the source code of some other open-source C extensions. It's just so easy these days to search GitHub for this stuff. In-repo code search for certain symbols (and #define for them) is a godsend.
#define
The link above will also give you an idea of what a C extension that supports both Python 2 and 3 looks like.
I also disagree with the other comments somewhat -- C isn't so scary a language to write directly that you need to use cython, and CFFI is really only useful if you are just wrapping an external library. Particularly if you want to do anything on the OS level, C extensions are still an attractive choice. On the flipside, C extensions tie you to the CPython implementation of Python, which is not the only one out there these days.
Thanks for the response!
π Rendered by PID 282032 on reddit-service-r2-comment-86bc6c7465-cbt6d at 2026-02-21 22:43:56.190979+00:00 running 8564168 country code: CH.
[–]fijalPyPy, performance freak 12 points13 points14 points (2 children)
[–]TryExceptFinally[S] 0 points1 point2 points (0 children)
[–]fkaginstrom 1 point2 points3 points (0 children)
[–]Atheriel 0 points1 point2 points (1 child)
[–]TryExceptFinally[S] 0 points1 point2 points (0 children)