Comments (2)
That's something like super()
, short for super(SomeClass, self)
.
This video has a rough implementation for it: https://www.youtube.com/watch?v=X1PQ7zzltz4
The idea is similar to the "vanilla solution" you mentioned, which uses current_frame.f_back.f_locals
to trace the local variables from the previous frame.
The core functions from varname
handle the variable names that are explicitly given. The implementation behind the scenes is similar to the "vanilla solution". However, the variable/arguments are hidden in your case, which is out of the scope of this package.
The function you wanted can be implemented with a very simple wrapper around that "vanilla solution":
import sys
def get_prev_local(name):
# frame 1: inside fun2
# frame 2: inside fun1
return sys._getframe(2).f_locals[name]
def fun1():
self = 1
fun2()
def fun2():
self = get_prev_local("self")
print(self)
fun1() # prints 1
from python-varname.
Close it for now. Feel free to reopen.
from python-varname.
Related Issues (20)
- How to get argname of chain function HOT 6
- Is there a way to get the argname with exec or eval HOT 4
- VarnameRetrievingError when run py script in debug mode in PyCharm HOT 2
- Errors on Python 3.9.7 HOT 3
- overload type returns for nameof HOT 6
- Error retrieving value for `__setitem__` HOT 5
- nameof error when running program, but not when running in debug HOT 13
- argname seems not working HOT 2
- Performance issues HOT 2
- VarnameRetrievingError when I use function as part of module HOT 10
- how to nameof inside a loop ? HOT 1
- how to get arg name in sub function? HOT 10
- argname doesn't seem to function, "cannot retrieve the node where the function is called" HOT 7
- How to print the variable names inside a for loop ? HOT 8
- some cases of argname don't know how to deal HOT 2
- Partial assignment in case a starred variable is present HOT 6
- "VarnameRetrievingError: Unable to retrieve the ast node." / "VarnameRetrievingError: Cannot retrieve the node where the function is called." HOT 1
- Traversal list HOT 1
- "Unable to retrieve the ast node" issue HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-varname.