Pointers and Objects in Python (Summary)
You now know how Python deals with objects and pointers! You learned about the differences between names and variables, which is important for understanding how Python handles variables. You also saw that you can simulate pointers in Python without sacrificing the memory safety that Python provides.
You can simulate pointers in Python by:
- Using mutable objects as low-overhead pointers
- Creating custom Python objects for ease of use
- Unlocking real pointers with the
ctypes
module
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00
We covered a lot in this course. You learned how pointers work in C, the difference between mutable and immutable objects in Python, how you can utilize mutable objects and classes to mimic pointer behavior, and how Python code can interface with C using the ctypes
module.
00:21 As you’ve learned, pointers don’t exactly exist in Python, but you can simulate the pass-by-reference behavior of pointers in Python, all without sacrificing the memory safety that Python provides. Using what you’ve learned in this course, you can write Python libraries that are easier to work with, and you can also encapsulate performance-critical parts of your Python code into C and pass pointers that way.
00:50 I’m Austin Cepalia with realpython.com. Thanks for watching this course and, as usual, happy coding!
Santosh on July 8, 2020
Great job! Loved the flow and presentation.
felixthec on July 8, 2020
:Applause: A very good and informative presentation.
Jordan Rowland on July 11, 2020
This was an awesome lesson! Very clear and concise. Bravo!
Hilman on July 11, 2020
Good presentation. A good refresh for me on C pointer. And this is my first time learning working with C type in python!
mahlenius on July 12, 2020
Great presentation. Very helpful. Its great that he calls out where Python is strong for some problems and weak for others.
thank you
Alex on July 15, 2020
awesome presentation!
anders stenborg martin on July 15, 2020
Great course, well presented!
carl on July 15, 2020
Nice presentation. Would love to see a more advanced course on using the ctypes module to call C functions for all sorts of argument types and return types.
srihariraju on Aug. 12, 2020
Good presentation
Ghani on Oct. 18, 2020
Very informative and clear; thank you so much!
g2sgautam on Dec. 20, 2020
I am getting an error
“TypeError: ‘CDLL’ object is not callable” on my Windows machine when I execute the code in 2nd last vide tutorial
Any solutions ?
Mark on Sept. 11, 2021
Great course, Austin. I’ve watched it three times to drill it in, and just wanted to drop a comment saying you’re a good teacher. All writers here on Real Python strike me as good, but I found you stood out. I’ll be looking for content from you in the future. I just felt compelled to pat you on the back for this course. Good job!
Joachim Spange on Dec. 12, 2022
Great course. After posting Add a pointer to image data in memory to acquisition queue, not the retrieved image data at stack overflow and not getting any answers within the coming days I watched this series. It was really insightfull and I now understand the complexity of the question I’m asking and why I’ll maybe never get a conclusive answer. I must roll up my sleeves and fix this with a C-function and CPython
Become a Member to join the conversation.
DFreyer on July 8, 2020
Very good Presentation. I learned a lot.