Section 22.4. Exercises


22.4. Exercises

22-1.

Extending Python. What are some of the advantages of Python extensions?

22-2.

Extending Python. Can you see any disadvantages or dangers of using extensions?

22-3.

Writing Extensions. Obtain or find a C/C++ compiler and write a small program with it to (re)familiarize yourself with C/C++ programming. Find your Python distribution directory and locate the Misc/Makefile.pre.in file. Take the program you just wrote and wrap it in Python. Go through the steps necessary to create a shared object. Access that module from Python and test it.

22-4.

Porting from Python to C. Take several of the exercises you did in earlier chapters and port them to C/C++ as extension modules.

22-5.

Wrapping C Code. Find a piece of C/C++ code, which you may have done a long time ago, but want to port to Python. Instead of porting, make it an extension module.

22-6.

Writing Extensions. In Exercise 13-3, you created a dollarize() function as part of a class to convert a floating point value to a financial numeric string with embedded dollar signs and commas. Create an extension featuring a wrapped dollarize() function and integrate a regression testing function, i.e., test(), into the module. Extra credit: In addition to creating a C extension, also rewrite dollarize() in Pyrex.

22-7.

Extending versus Embedding. What is the difference between extending and embedding?



Core Python Programming
Core Python Programming (2nd Edition)
ISBN: 0132269937
EAN: 2147483647
Year: 2004
Pages: 334
Authors: Wesley J Chun

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net