Docs for the internals of CPython Implementation - python

I am currently in the process of making an embedded system port of the CPython 3.0 Python interpreter and I'm particularly interested in any references or documentation that provides details about the design and structure of code for Release 3.0 or even about any of the 2.x releases.
One useful document I have found so far is this informational PEP on the implementation - which is a good overview - but is still pretty high level. Hoping to come across something that gives [much] more detail on more of the modules or perhaps even covers something about porting considerations.

There's the documentation for the C API, which is essentially the API for the internals of Python. It won't cover porting details, though. The code itself is fairly well documented. You might try reading in and around the area you'll need to modify.

Most of the documentation is stored in the minds of various core developers. :) A good resource for you would be the #python-dev IRC channel on freenode where many of them hang out.
There's also some scattered information on the Python wiki.

Related

KNX and KNXnet/IP implementation in Python

I am looking high and low for anything related to KNX implementation in Python, especially KNXnet/IP. So far I couldn't find anything. I know there are few projects written in Java but I thought I'd give it a shot asking here before I start porting code from other languages.
Also, does anyone know of any free documentation of the KNX standard, its data structures and KNXnet/IP? The official documentation from the KNX association is ridiculously expensive, especially for something supposed to be an "open" standard.
thanks
The KNX association have released the Falcon Runtime Developer kit but I think you can only get it if you are a KNX member. it doesnt supports Python but hey, its something i guess.
in regards to the documentation I could probably help.
is there a PM function on this site or something to give me your emails address?
There is the open-source BCUSDK software stack for KNX which has a C-based system daemon (eibd) with clients (Unix and TCP-socket based) for multiple languages (Python is one). I've written the Ruby and Lua client libraries as well, and I'm using it for day-to-day hacking with KNX.
Also, there is OpenRemote which has lots of information on KNXnet/IP and some Java classes that could get you started, if you wanted to, from scratch.
You might want to have a look a this (if by that time you are still looking for such a library) : https://github.com/leadrien/knxnet
This allows me to command KNX devices through an IP/KNX interface pretty well.
Alexandre
Meanwhile there is an open source Python 3 implementation of KNX IP https://github.com/XKNX/xknx
The documentation of the protocol can be downloaded after (free) registration from https://my.knx.org

Extending the code of Python - adding language features

I have been programming in python exclusively for 4 years and have never really looked under the hood at the C code in which python is written. I have recently been looking into a problem that would involve modifying python at that level.
The code seems pretty consistent, and thus relatively easily understood. However, it's complex enough that it wasn't making sense to me just by studying it how it all worked together. Granted, I didn't spend a lot of time or effort on that, for want of a better resource. I also looked over the documentation on the python site. However, it is oriented more toward extending the language through modules.
I was hoping to find some straightforward documentation on how the parser works at the C level and how to extend the core language directly (adding language features). The module-oriented documentation provides some great insight into the way types are built and objects are managed, but I am looking for more.
Is there any such documentation out there?
This article may help you get started. It takes a lot of information from the excellent PEP 339 - Design of the CPython Compiler.
http://docs.python.org/extending/index.html - Custom modules/extensions
http://docs.python.org/c-api/index.html - C API, under the hood
There's not too much written lore on this topic. Your best bet is to just simply follow the guidelines in PEP 306

Is there any thorough, broad documentation of Twisted that is better than the official site?

I've been looking at twisted for a while now. It looks interesting - it seems like a good way to leverage a lot of power when writing servers. Unfortunately, in spite of writing a few web servers using twisted.web (from reading other people's source and an extremely dated O'Reilly book) I've never really felt like I had reached an affinity with twisted... a level of understanding that actually gave me some of the power it seems like it has.
I think I need some good documentation to arrive at a better level of understanding - I simply don't have time to pore over the source, and other threads on SO have mentioned twisted's official documentation, which is patchy at best, absent at worst, and occasionally very out of date.
Is there anything else out there that is more thorough, more forgiving, and more useful, or am I stuck with another classic, boring STFU and RTFM even though TFM is not helpful?
Update
In response to JP Calderone's comment that I'm just having a bitch, to some extent I guess I am, but I think the breadth of the question is valid considering the breadth and value of Twisted and the lack of obvious, thorough documentation. I have a few things in mind that I wanted to investigate, but I've been getting OK results just hacking things together and asking for specifics when a deeper, broader understanding is what I'm looking for is, in my mind, not helpful.
The contrast that immediately springs to mind is Django... I can read over the (very thorough) Django documentation and not necessarily know how to do everything it can do immediately, but I can get a really good overview of how I might do everything I needed to do, and know exactly where to look when the time comes.
I'm going to repeat what some of the answerers here have said (they're all good answers) in the hopes of providing an answer that is somewhat comprehensive.
While the included documentation is spotty in places, the core documentation contains several helpful and brief introductions to the basic concepts in Twisted. Especially, see Using Deferreds, Writing Clients and Writing Servers.
Also, the API documentation - especially the documentation in interface modules - is increasingly thorough and coherent with each subsequent release.
If you're interested in a higher-level description of Twisted's goals and design so you know how to approach some of this other documentation, I co-authored a paper presented at USENIX 2003 with Itamar Turner-Trauring.
Twisted's FAQ is also a bit meandering, but may help you with many stumbling blocks that people hit when working their way through introductory material.
The O'Reilly book about Twisted has some great examples which may further elucidate core concepts like Deferreds and the Reactor.
Jean-Paul Calderone's "Twisted Web In 60 Seconds" tutorials are a good introduction to the somewhat higher-level twisted.web, of course, but you will also see lots of useful patterns repeated throughout which may be useful to you in whatever application you're writing.
I have written a pair of articles on building-blocks used within Twisted, to deal with the filesystem and to load plugins.
Last but certainly not least, Dave Peticolas's modestly titled "Twisted Intro" is a very comprehensive description, with diagrams and anecdotes, on the introductory material that so many people have difficulty with.
Please also note that all new functionality comes with new API (i.e. reference) documentation; we hope that this will make it more reasonable for people with technical writing skills to write documentation without having to struggle through even understanding what the method names mean.
The Twisted Intro by Dave Peticolas is an amazing overview of Twisted from the ground up. It starts simple and then starts getting deeper and deeper while explaining everything along the way.
I've been using Twisted for years and found this intro to fill in all those gaps I was missing and shed light on the whole thing. Definitely worth your time to check it out!
Check Twisted Web in 60 seconds by Jean-Paul Calderone!
But, honestly, the Twisted's official documentation is not perfect but I'll not call it disgusting. There's a lot of valuable info in it.
Take a look at this previous post...
Python twisted: where to start
There's the O'Reilly book Twisted Network Programming Essentials.
I have not read it, but the ToC looks nice enough.

python - good places to check out example prog / code online?

there is a year old, similar question - but in case there have been changes afoot:
i'm an intermediate c++ programmer just starting out on python, post some online tuts etc i can do some basic pythoneering, but was wondering if there are good places i can look online for simple(ish) --pref console based-- code that i can learn from, ideally with some sort of commentary.
anything come to mind?
thanks
The standard library is an excellent place to the start. It's maintained by the core python team and is of high quality with a lot of interesting idioms. I'd recommend the newer modules since they don't have much backward compatibility cruft and are more representative of the language as it is now. The older ones were written for earlier versions of Python and have some restrictions when it comes to API changes etc.
The list of modules in the standard library is described at http://docs.python.org/library/. You can go through it and decide which one you want to look at (area of interest etc.).
Their sources are viewable at the mercurial repo here http://hg.python.org/cpython/file/d7e85ddb1336/Lib (as of today). These are for the mainline 2.6 release. You can also checkout the repo and browse it on your local machine.
You can also start up your interpreter, import a module (say os) and do a print os.__file__ to see where the source file is if you want to look at the code in your local editor.
ActiveState Recipes is a good source for all kinds of Python scripts. But if you want to learn the basics of Python, you might just want to look at the standard library that ships with Python ("lib" directory").
i came across This The other day, Probably you can learn some python basics and have a laugh too!
Anyways, look at the libs as they said above, they are very useful
If you enjoy riddles:
www.pythonchallenge.com
If you're an intermediate C++ programmer, you're already equipped to handle to programming concepts. I like it because it gives me a reason to learn each part of the language, without being mundane 'Hello World' tasks.
However, some of the riddles are pretty tough and/or unrelated to programming. Either way, doing the first few will probably be enough to get your confidence up with Python syntax.

Why is the PyObjC documentation so bad? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
For example, http://developer.apple.com/cocoa/pyobjc.html is still for OS X 10.4 Tiger, not 10.5 Leopard.. And that's the official Apple documentation for it..
The official PyObjC page is equally bad, http://pyobjc.sourceforge.net/
It's so bad it's baffling.. I'm considering learning Ruby primarily because the RubyCocoa stuff is so much better documented, and there's lots of decent tutorials (http://www.rubycocoa.com/ for example), and because of the Shoes GUI toolkit..
Even this badly-auto-translated Japanese tutorial is more useful than the rest of the documentation I could find..
All I want to do is create fairly simple Python applications with Cocoa GUI's..
Can anyone shed light on the horrible documentation, or point me at some tutorials that don't just give you huge blocks of code and assume you know what NSThread.detachNewThreadSelector_toTarget_withObject_("queryController", self, None) does..?
The main reason for the lack of documentation for PyObjC is that there is one developer (me), and as most developers I don't particularly like writing documentation. Because PyObjC is a side project for me I tend to focus on working on features and bugfixes, because that's more interesting for me.
The best way to improve the documentation is to volunteer to help on the pyobjc-dev mailing list.
As an aside: the pythonmac-sig mailinglist (see google) is an excelent resource for getting help on Python on MacOSX (not just PyObjC).
I agree that that tutorial is flawed, throwing random, unexplained code right in front of your eyes. It introduces concepts such as the autorelease pool and user defaults without explaining why you would want them ("Autorelease pool for memory management" is hardly an explanation).
That said…
basically all I want to do is write Cocoa applications without having to learn ObjC.
I'm afraid that for the time being, you will need a basic grasp of ObjC in order to benefit from any language that uses Cocoa. PyObjC, RubyCocoa, Nu and others are niches at best, and all of them were developed by people intimately familiar with the ins and outs of ObjC and Cocoa.
For now, you will benefit the most if you realistically see those bridges as useful where scripting languages truly shine, rather than trying to build a whole application with them. While this has been done (with LimeChat, I'm using a RubyCocoa-written app right now), it is rare and likely will be for a while.
To be blunt:
If you want to be an effective Cocoa programmer, you must learn Objective-C. End of story.
Neither Python or Ruby are a substitute for Objective-C via their respective bridges. You still have to understand the Objective-C APIs, the behaviors inherent to NSObject derived classes, and many other details of Cocoa.
PyObjC and RubyCocoa are a great way to access Python or Ruby functionality from a Cocoa application, including building a Cocoa application mostly -- if not entirely -- in Python or Ruby. But success therein is founded upon a thorough understanding of Cocoa and the Objective-C APIs it is composed of.
Tom's and Martin's response are definitely true (in just about any open source project, you'll find that most contributors are particularly interested in, well, developing; not so much in semi-related matters such as documentation), but I don't think your particular question at the end would fit well inside PyObjC documentation.
NSThread.detachNewThreadSelector_toTarget_withObject_("queryController", self, None)
NSThread is part of the Cocoa API, and as such documented over at Apple, including the particular method + detachNewThreadSelector:toTarget:withObject: (I'd link there, but apparently stackoverflow has bugs with parsing it). The CocoaDev wiki also has an article.
I don't think it would be a good idea for PyObjC to attempt to document Cocoa, other than a few basic examples of how to use it from within Python. Explaining selectors is also likely outside the scope of PyObjC, as those, too, are a feature of Objective-C, not PyObjC specifically.
I stumbled across a good tutorial on PyObjC/Cocoa:
http://lethain.com/entry/2008/aug/22/an-epic-introduction-to-pyobjc-and-cocoa/
All I want to do is create fairly simple Python applications with Cocoa GUI's.. Can anyone shed light on the horrible documentation, or point me at some tutorials that don't just give you huge blocks of code and assume you know what NSThread.detachNewThreadSelector_toTarget_withObject_("queryController", self, None) does..?
[...]
basically all I want to do is write Cocoa applications without having to learn ObjC.
Although I basically agree with Soeren's response, I'd take it even further:
It will be a long time, if ever, before you can use Cocoa without some understanding of Objective C. Cocoa isn't an abstraction built independently from Objective C, it is explicitly tied to it. You can see this in the example line of code you quoted above:
NSThread.detachNewThreadSelector_toTarget_withObject_("queryController", self, None)
This is the Python way of writing the Objective C line:
[NSThread detachNewThreadSelector:#selector(queryController:) toTarget:self withObject:nil];
Now, it's important to notice here that this line can be seen in two ways: (1) as a line of Objective C, or (2) as an invocation of the Cocoa frameworks. We see it as (1) by the syntax. We see it as (2) by recognizing that NSThread is a Cocoa framework which provides a set of handy features. In this case, this particular Cocoa framework is making it easy for us to have an object start doing something on a new thread.
But the kicker is this: The Cocoa framework here (NSThread) is providing us this handy service in a way that is explicitly tied to the language the framework has been written in. Namely, NSThread gave us a feature that explicitly refers to "selectors". Selectors are, in point of fact, the name for something fundamental about how Objective C works.
So there's the rub. Cocoa is fundamentally an Objective-C creation, and its creators have built it with Objective C in mind. I'm not claiming that it's impossible to translate the interface to the Cocoa features into a form more natural for other languages. It's just that as soon as you change the Cocoa framework to stop referring to "selectors", it's not really the Cocoa framework any more. It's a translated version. And once you start going down that road, I'm guessing things get really messy. You're trying to keep up with Apple as they update Cocoa, maybe you hit some parts of Cocoa that just don't translate well into the new language, whatever. So instead, things like PyObjC opt to expose Cocoa directly, in a way that has a very clear and simple correlation. As they say in the documentation:
In order to have a lossless and unambiguous translation between Objective-C messages and Python methods, the Python method name equivalent is simply the selector with colons replaced by underscores.
Sure, it's a bit ugly, and it does mean you need to know something about Objective-C, but that's because the alternative, if one truly exists, is not necessarily better.
I didn't know anything at all about Objective C or Cocoa (but plenty about Python), but I am now writing a rather complex application in PyObjc. How did I learn? I picked up Cocoa Programming for OSX and went through the whole book (a pretty quick process) using PyObjC. Just ignore anything about memory management and you'll pretty much be fine. The only caveat is that very occasionally you have to use a decorator like endSheetMethod (actually I think that's the only one I've hit):
#PyObjcTools.AppHelper.endSheetMethod
def alertEnded_code_context_(self, alert, choice, context):
pass
This answer isn't going to be very helpful but, as a developer I hate doing documentation. This being a opensource project, it's hard to find people to do documentation.
Tom says it all really. Lots of open source projects have dedicated developers and few who are interested in documenting. It isn't helped by the fact that goalposts can shift on a daily basis which means documentation not only has to be created, but maintained.

Categories

Resources