Python extensions tutorial
|1600||Tea break (10 minutes)||165|
|Number of days||2|
|Day 1 morning||165||Introduction and basics|
|Day 1 afternoon||255|
|Day 2 morning||165|
|Day 2 afternoon||255||Packaging and distribution|
Aims of the course
- Contact me for system setup if you need help +919880240460
- Prerequisites should be done before the training
Introduction to extensions
Structure of the course
- Familiarise with Python/C API
- Innards of the interpreter
- What we aim to do (libcsv)
- TDD (using py.test)
- Live sessions
- System setup
- Extra downloads
- Quick overview of how to use libcsv to parse a “large” CSV file
and print out fields.
- Compile and run a few programs to display information as well as
Structure of a Python module written in C
- _ccsv.so and ccsv.py with the latter for import.
- Directories and stuff
- Various structures and what they represent
- Reference counts
- Custom types (new classes)
- Creating a new class
- Class methods
- Objects of the class
- Object methods
- Exposing elements of the class
- Create a file like object with some extra methods
- Number of lines, column headers etc.
- Need to redo this based on what’s provided by the libcsv
C program using libcsv
Things to include
- Packaging the module
- Options to the
- Intialisation and
- Callback based parsing. Pass Python functions in here.
- Changing options
- Error handling!
Overall module design.
- Implement writing CSV files
Notes on stages
- Initialise file like parser object with file name
- We should be able to do a
for i in fp and get back rows.
- We can change parameters on the fly with a set_something (or
descriptors - even better).
- Set an exception in a global variable.
Mention problems with the way we’re executing the callback functions
Spend some time on Reference counts.