The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Python FAQ. Can I create my own functions in C or C++? video tutorial: Extending Python With C
By Guest on 7th November 2022 07:47:53 AM | Syntax: PYTHON | Views: 183



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1. Can I create my own functions in C?
  2. ===================================
  3.  
  4. Yes, you can create built-in modules containing functions, variables, exceptions and even new types in C.  This is explained in the document
  5. Extending and Embedding the Python Interpreter.
  6.  
  7. Most intermediate or advanced Python books will also cover this topic.
  8.  
  9.  
  10. Can I create my own functions in C++?
  11. =====================================
  12.  
  13. Yes, using the C compatibility features found in C++.  Place "extern
  14. "C" { ... }" around the Python include files and put "extern "C""
  15. before each function that is going to be called by the Python
  16. interpreter.  Global or static C++ objects with constructors are
  17. probably not a good idea.
  18.  
  19.  
  20. Writing C is hard; are there any alternatives?
  21. ==============================================
  22.  
  23. There are a number of alternatives to writing your own C extensions,
  24. depending on what you're trying to do.
  25.  
  26. Cython and its relative Pyrex are compilers that accept a slightly
  27. modified form of Python and generate the corresponding C code.  Cython
  28. and Pyrex make it possible to write an extension without having to
  29. learn Python's C API.
  30.  
  31. If you need to interface to some C or C++ library for which no Python
  32. extension currently exists, you can try wrapping the library's data
  33. types and functions with a tool such as SWIG.  SIP, CXX Boost, or
  34. Weave are also alternatives for wrapping C++ libraries.
  35.  
  36.  
  37. Watch: Extending Python With C
















Python software and documentation are licensed under the PSF License Agreement.
Starting with Python 3.8.6, examples, recipes, and other code in the documentation are dual licensed under the PSF License Agreement and the Zero-Clause BSD license.
Some software incorporated into Python is under different licenses. The licenses are listed with code falling under that license. See Licenses and Acknowledgements for Incorporated Software for an incomplete list of these licenses.

Python and it's documentation is:
Copyright © 2001-2022 Python Software Foundation. All rights reserved.
Copyright © 2000 BeOpen.com. All rights reserved.
Copyright © 1995-2000 Corporation for National Research Initiatives. All rights reserved.
Copyright © 1991-1995 Stichting Mathematisch Centrum. All rights reserved.

See History and License for complete license and permissions information:
https://docs.python.org/3/license.html#psf-license
  • Recent Pastes