ctypes.cast.

>>> import ctypes
>>> c_long_p = ctypes.POINTER(ctypes.c_long)
>>> some_long = ctypes.c_long(42)
>>> ctypes.addressof(some_long)
4300833936
>>> ctypes.cast(4300833936, c_long_p)
<__main__.LP_c_long object at 0x1005983b0>
>>> ctypes.cast(4300833936, c_long_p).contents
c_long(42)
Answer from habnabit on Stack Overflow
🌐
tentacles666
tentacles666.wordpress.com › 2012 › 01 › 21 › python-ctypes-dereferencing-a-pointer-to-a-c
Python ctypes: dereferencing a pointer to a C structure | tentacles666
March 19, 2013 - First, you need to define a Python class that represents struct foo: class Foo (ctypes.Structure): _fields_ = [ ("bar", c_int) ] Next, you need to tell ctypes that newfoo() returns a pointer to such a thing: mylib.newfoo.restype = POINTER(Foo) Finally, after invoking newfoo(), you need to use the pointer’s contents member to dereference it: p = mylib.newfoo() p.contents.bar = 17 ·
Discussions

[FEAT] being able to enforce the dereferencing of the smart pointer in argument conversion
I have a relatively complex ("externally given") class with a funny ownership model, so things can go missing while Python has a reference. To wrap it in Python safely, I'm trying to hold instances in a smart pointer (a la shared_ptr) that checks on dereferencing whether the referred to object ... More on github.com
🌐 github.com
21
December 29, 2020
Why is there no concept of a pointer or pass-by reference in python? Is there something I can use
Holy cow calm down. EXCEPT THERE IS NO TRUE MULTITHREADING Lol yes there is. The threading module makes real threads. If you are upset about the GIL you just need to learn how to use it. why is there no pointers!? All python names are pointers. It's incredibly hard not to use a pointer. No idea what you are doing but if you mutate a dictionary in a function you will see it in the calling scope. >>> def add_data(d): ... d['Fuck-Me-With-RAM'] = 'pure zen' ... >>> data = {} >>> add_data(data) >>> data {'Fuck-Me-With-RAM': 'pure zen'} Read this: https://nedbatchelder.com/text/names.html this junk language Cheers, don't let the door hit ya More on reddit.com
🌐 r/learnpython
16
0
August 10, 2022
🌐
Real Python
realpython.com › pointers-in-python
Pointers in Python: What's the Point? – Real Python
March 18, 2026 - Pointers are widely used in C and C++. Essentially, they are variables that hold the memory address of another variable. For a refresher on pointers, you might consider checking out this overview on C Pointers. In this article, you’ll gain a better understanding of Python’s object model and learn why pointers in Python don’t really exist.
🌐
PyPI
pypi.org › project › pointers.py › 1.0.5
pointers.py
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Python
docs.python.org › 2.5 › lib › ctypes-pointers.html
14.14.1.14 Pointers
December 23, 2008 - >>> null_ptr = POINTER(c_int)() >>> print bool(null_ptr) False >>> ctypes checks for NULL when dereferencing pointers (but dereferencing non-NULL pointers would crash Python):
🌐
Medium
medium.com › @mengdaliu › moving-from-a-programming-language-eg-cf114c403607
Pointers in Python v.s. Pointers in Golang | by Shar-Pei Dog | Medium
June 17, 2019 - Besides using the non-local statement in Python, the answer is to pass in a pointer variable, dereference it inside the function to get what’s actually held in the memory address, and then change the data directly.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › pointers in python
Pointers in Python | Type of Pointers | Arithmetic Operations
August 23, 2025 - Variables which serve the special purpose of storing the address of other variables, pointing to the address of the variable of which the address is provided, with obtaining of the value stored at the location being called dereferencing, like ...
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
GitHub
github.com › pybind › pybind11 › issues › 2751
[FEAT] being able to enforce the dereferencing of the smart pointer in argument conversion · Issue #2751 · pybind/pybind11
December 29, 2020 - I have a relatively complex ("externally given") class with a funny ownership model, so things can go missing while Python has a reference. To wrap it in Python safely, I'm trying to hold instances in a smart pointer (a la shared_ptr) that checks on dereferencing whether the referred to object ...
Author: pybind
Find elsewhere
🌐
Python
bugs.python.org › issue24044
Issue 24044: NULL pointer dereference in listsort() with key function - Python tracker
April 23, 2015 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/68232
🌐
Google Groups
groups.google.com › g › cython-users › c › uul_h95lKqM
cannot dereference pointer
> Okay, I'm trying to convert a python object and return the equivalent > C type. I have one of each C type declared on the stack in the > calling code and passed by pointer to the conversion function. I hope > it's clear what I'm trying to do, even if it isn't elegant. I'm > getting errors such as the following, one for each pointer I'm trying > to dereference: > > Cannot assign type 'int' to 'int *' > > So the dereference isn't understood?
🌐
Reddit
reddit.com › r/learnpython › why is there no concept of a pointer or pass-by reference in python? is there something i can use
r/learnpython on Reddit: Why is there no concept of a pointer or pass-by reference in python? Is there something I can use
August 10, 2022 -

I am a C++ and assembly developer mainly, but as someone entering the job market that just doesn't cut it. I have a job I got hired for where I'm taking 4+ years of a python codebase that no one has documented and is spaghetti and updating it, and was supposed to be adding multithreading (EXCEPT THERE IS NO TRUE MULTITHREADING SO I HAVE TO DO MULTIPROCESSING WHICH IS A CLUSTER-F***). So that blows.

BUT

why is there no pointers!? or way to go references? I need to store data in an object that gets passed into some libraries, and then the library runs callbacks where I analyze the crap. From there I need to set the values so in other callbacks I can work with the values. It's a dictionary so I can add some new keys to store the data... except I can't because it's like pass by value so the data instantly gets deleted once it returns from the callback. If I passed in a pointer I'd be set, except that's not possible...

That's just one issue in a mirad of issues I'm facing with this junk language. Not to even mention the horribleness of everything using like 2gb of memory because each process copies the entire memory space of the head process....

Please tell me there's some kinda object or pointer thing I can use.

EDIT : I got the help I needed here, thanks everyone! sorry to trash the language a bit above I was just frustrated lol

Top answer
1 of 4
13
Holy cow calm down. EXCEPT THERE IS NO TRUE MULTITHREADING Lol yes there is. The threading module makes real threads. If you are upset about the GIL you just need to learn how to use it. why is there no pointers!? All python names are pointers. It's incredibly hard not to use a pointer. No idea what you are doing but if you mutate a dictionary in a function you will see it in the calling scope. >>> def add_data(d): ... d['Fuck-Me-With-RAM'] = 'pure zen' ... >>> data = {} >>> add_data(data) >>> data {'Fuck-Me-With-RAM': 'pure zen'} Read this: https://nedbatchelder.com/text/names.html this junk language Cheers, don't let the door hit ya
2 of 4
4
EXCEPT THERE IS NO TRUE MULTITHREADING SO I HAVE TO DO MULTIPROCESSING WHICH IS A CLUSTER-F*** If that's an issue for you then someone used the wrong tool for the wrong job. That said: most of the time asyncio's single-threaded event loop will do just fine. why is there no pointers!? Why should there be? It's a high-level language with a garbage collector. or way to go references? For any collection type or class you're already getting effectively pass-by-reference, but if you mean why won't def foo(x): x = 2 x = 1 foo(x) # x is still 1 here change x to 2: because in python there's no reason it should. Spooky action at a distance is generally discouraged and, just like in C/C++ you should avoid when you reasonably can. It's a dictionary so I can add some new keys to store the data... except I can't because it's like pass by value so the data instantly gets deleted once it returns from the callback. Dictionaries are not passed by value. def foo(x): x["new_key"] = "it's here" y = {} foo(y) print(y) A bit more technically: everything is effectively passed by reference, the language simply (deliberately) has immutable values for integers, floats, strings, and most 'primitive' types like that so there exists no way to express the concept of "edit the value of the python object this variable currently points at" for those primitives. The concept absolutely does exist for objects in general - anything done via the name (as opposed to reassigning the name) acts on the underlying python object. That's why the dictionary key is persisted in y outside the function in my example.
🌐
Python Morsels
pythonmorsels.com › pointers
Variables and objects in Python - Python Morsels
February 28, 2022 - Variables in Python are not buckets containing things; they're pointers (they point to objects). The word "pointer" may sound scary, but a lot of that scariness comes from related concepts (e.g. dereferencing) which aren't relevant in Python.
🌐
Netlify
pointerspy.netlify.app › reference
Reference - pointers.py
Class representing a pointer with a known type. ... Dereference the pointer.
🌐
GeeksforGeeks
geeksforgeeks.org › using-pointers-in-python-using-ctypes
Using Pointers in Python using ctypes - GeeksforGeeks
January 9, 2023 - In languages like C/C++ pointers ... that pointer variable i.e while printing it we put the certain format specifier and then use an asterisk (*) with that variable to get the value it was pointing....
🌐
Lenovo
lenovo.com › home
Everything You Need to Know About the Dereference Operator | Lenovo UK
The dereference operator (*) and the address-of operator (&) are complementary. The address-of operator is used to obtain the memory address of a variable, while the dereference operator is used to access the value stored at a memory address pointed to by a pointer.
🌐
Sololearn
sololearn.com › en › Discuss › 1609533 › what-is-the-difference-between-dereference-and-pointers
What is the difference between dereference and pointers? | Sololearn: Learn to code for FREE!
December 4, 2018 - The difference is simple. If there is a type on the left of the *, then it is a pointer declaration, otherwise it a pointer dereference operation, provided the operand on the right is a pointer.
🌐
Duke
jupyternotebooks-dpb6-e8e09e2d24a591fa64baaf90dc750c5415a29cf5e.pages.oit.duke.edu › 3-CPlusCPlus › 13-Pointers › 13-Pointers.html
13. Pointers — Programming for Financial Technology
To access the contents of the memory location that a pointer references, we use the unary operator * (dereferences). Going back to the third Python notebook, you can equate this address to the address of a building in a city - it just references a location in memory.
🌐
Llllllllll
llllllllll.github.io › principles-of-performance › python-overview.html
Python Overview — principles-of-performance documentation
Because the size of each value differs depending on the type, which cannot be known ahead of time because Python is dynamically typed, Python just refers to all objects through a pointer to the value struct. All we know is that the first member of the value struct will be a pointer to some collection of functions which will be designed to know the true size of the object and how to interpret the data. This means that at minimum we must do one memory dereference to perform any operation on a Python object.
🌐
GitHub
github.com › python › cpython › issues › 126106
Potential null pointer dereference in `PySSLSession_richcompare` · Issue #126106 · python/cpython
October 29, 2024 - Bug report Bug description: Pointer left is dereferenced here, but null-pointer check is done later. Correct code should look like this: int result; if (left == NULL || right == NULL) { PyErr_BadInternalCall(); return NULL; } PyTypeObjec...
Author: python