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. How to create object class with some methods implemented in C and others in Python? Bridging between Python and C/C++
By Guest on 7th November 2022 08:31:13 AM | Syntax: PYTHON | Views: 159



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1. I added a module using the Setup file and the make fails; why?
  2. ==============================================================
  3.  
  4. Setup must end in a newline, if there is no newline there, the build
  5. process fails.  (Fixing this requires some ugly shell script hackery,
  6. and this bug is so minor that it doesn't seem worth the effort.)
  7.  
  8.  
  9. How do I debug an extension?
  10. ============================
  11.  
  12. When using GDB with dynamically loaded extensions, you can't set a
  13. breakpoint in your extension until your extension is loaded.
  14.  
  15. In your ".gdbinit" file (or interactively), add the command:
  16.  
  17.    br _PyImport_LoadDynamicModule
  18.  
  19. Then, when you run GDB:
  20.  
  21.    $ gdb /local/bin/python
  22.    gdb) run myscript.py
  23.    gdb) continue # repeat until your extension is loaded
  24.    gdb) finish   # so that your extension is loaded
  25.    gdb) br myfunction.c:50
  26.    gdb) continue
  27.  
  28.  
  29. I want to compile a Python module on my Linux system, but some files are missing. Why?
  30. ======================================================================================
  31.  
  32. Most packaged versions of Python don't include the
  33. "/usr/lib/python2.*x*/config/" directory, which contains various files
  34. required for compiling Python extensions.
  35.  
  36. For Red Hat, install the python-devel RPM to get the necessary files.
  37.  
  38. For Debian, run "apt-get install python-dev".
  39.  
  40.  
  41. How do I tell "incomplete input" from "invalid input"?
  42. ======================================================
  43.  
  44. Sometimes you want to emulate the Python interactive interpreter's
  45. behavior, where it gives you a continuation prompt when the input is
  46. incomplete (e.g. you typed the start of an "if" statement or you
  47. didn't close your parentheses or triple string quotes), but it gives
  48. you a syntax error message immediately when the input is invalid.
  49.  
  50. In Python you can use the "codeop" module, which approximates the
  51. parser's behavior sufficiently.  IDLE uses this, for example.
  52.  
  53. The easiest way to do it in C is to call "PyRun_InteractiveLoop()"
  54. (perhaps in a separate thread) and let the Python interpreter handle
  55. the input for you. You can also set the
  56. "PyOS_ReadlineFunctionPointer()" to point at your custom input
  57. function. See "Modules/readline.c" and "Parser/myreadline.c" for more
  58. hints.
  59.  
  60.  
  61. How do I find undefined g++ symbols __builtin_new or __pure_virtual?
  62. ====================================================================
  63.  
  64. To dynamically load g++ extension modules, you must recompile Python,
  65. relink it using g++ (change LINKCC in the Python Modules Makefile),
  66. and link your extension module using g++ (e.g., "g++ -shared -o
  67. mymodule.so mymodule.o").
  68.  
  69.  
  70. Can I create an object class with some methods implemented in C and others in Python (e.g. through inheritance)?
  71. ================================================================================================================
  72.  
  73. Yes, you can inherit from built-in classes such as "int", "list",
  74. "dict", etc.
  75.  
  76. The Boost Python Library (BPL,
  77. https://www.boost.org/libs/python/doc/index.html) provides a way of
  78. doing this from C++ (i.e. you can inherit from an extension class
  79. written in C++ using the BPL).
  80.  
  81.  
  82. Cython Tutorial - Bridging between Python and C/C++ for performance gains
  83. https://www.youtube.com/watch?v=mXuEoqK4bEc
















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