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
🌐
GeeksforGeeks
geeksforgeeks.org › using-pointers-in-python-using-ctypes
Using Pointers in Python using ctypes - GeeksforGeeks
January 9, 2023 - # Importing ctypes module import ... Here we are checking if really we were able to successfully make a Null Pointer. bool() function of Python can be used for this Purpose, the boolean value of the Null Pointer will always ...
Discussions

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
[FEAT] being able to enforce the dereferencing of the smart pointer in argument conversion
Thank you for making PyBind11! 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 Py... More on github.com
🌐 github.com
21
December 29, 2020
python - Is it possible to dereference variable id's? - Stack Overflow
Can you dereference a variable id retrieved from the id function in Python? For example: dereference(id(a)) == a I want to know from an academic standpoint; I understand that there are more practi... More on stackoverflow.com
🌐 stackoverflow.com
Why doesn't Python have pointers?
What’s a pointer More on reddit.com
🌐 r/learnpython
63
128
April 21, 2023
🌐
Python
docs.python.org › 2.5 › lib › ctypes-pointers.html
14.14.1.14 Pointers
December 23, 2008 - Calling the pointer type without an argument creates a NULL pointer. NULL pointers have a False boolean value: >>> 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):
🌐
Real Python
realpython.com › pointers-in-python
Pointers in Python: What's the Point? – Real Python
March 18, 2026 - This is especially true when you’re navigating the tricky subject of pointers in Python. To help drive home the difference, you can take a look at how variables work in C, what they represent, and then contrast that with how names work in Python. Let’s say you had the following code that defines the variable x: ... Here, you can see that the variable x has a fake memory location of 0x7f1 and the value 2337.
🌐
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.
🌐
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 ·
🌐
Ubuntu Forums
ubuntuforums.org › archive › index.php › t-895804.html
[SOLVED] Pointers in Python? [Archive] - Ubuntu Forums
In a C-ish way, let's say in Python everything is a pointer (passed by reference, is the technical term). :) To check if an object is the same as another (the same instance), use the 'is' operator, not '=='. ('is' is like comparing pointers and '==' like comparing the values of the dereferenced pointers).
🌐
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 a page number in the index of a book that drives the reader to the required content, with performance for repetitive operations like traversing data structures being significantly improved, especially in terms of time and space constraints, supporting the copy and access operations effectively, and are indirectly supported as a concept by Python programming language are termed as pointers in Python. ... Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Find elsewhere
🌐
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 - There is an "obvious path" to go through lambdas that all take the smart pointer and dereference themselves, but this is obviously a bit cumbersome when it needs to be done to a large number of methods.
Author: pybind
🌐
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
🌐
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.
🌐
CodersLegacy
coderslegacy.com › home › python › using pointers with ctypes and python
Using Pointers with Ctypes and Python - CodersLegacy
July 8, 2022 - Take a look at the following code: ... function. The pointer() function will then return a pointer object. By using the .contents attribute, we can dereference a pointer and gain access to the original object it was pointing ...
🌐
Google Groups
groups.google.com › g › cython-users › c › uul_h95lKqM
cannot dereference pointer
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? I want the python-to-C type > conversion to occur and assign to the appropriate dereferenced C > value.
🌐
Notebook Community
notebook.community › tleonhardt › LearningCython › Learning_Cython_video › Chapter05 › pointers › pointers
Pointers in Cython
%%cython # Just a typical double cdef double x = 3.14159 # A pointer to a double. Give it the memory location of x cdef double* px = &x # Dereference using array access print(px[0]) ... %%cython # cython: language_level=3 cdef f(int* px): """ Hee Hee! Let's modify the value that this pointer is pointing to.
🌐
Lenovo
lenovo.com › home
Everything You Need to Know About the Dereference Operator | Lenovo UK
To assign a value to the pointer, you can use the address-of operator (&) with a variable, like ptr = &myVariable;, where myVariable is the variable whose address you want to store in ptr. Dereferencing a pointer means accessing the value stored at the memory address pointed to by that pointer.
🌐
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 - The freedom in programming added by the options to use value variables and to dereference pointer variables are not limited to cases where functions are used. It generalizes to any occasion where one piece of data is used in many places (multiple OOP instances, multiple arrays, etc.) and we want/ don’t want it to change in multiple places when we make change to it in one place. In fact, I was illustrating the different behaviors and effects of value/pointer variables with the usage of functions only because functions are fun, as they also introduce the tricky concepts of scopes and frame.