Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Profanity is the one language all programmers know best.


devel / comp.lang.python / Re: Introspecting the variable bound to a function argument

SubjectAuthor
o Re: Introspecting the variable bound to a function argumentBarry

1
Re: Introspecting the variable bound to a function argument

<mailman.1918.1677086525.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21823&group=comp.lang.python#21823

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: bar...@barrys-emacs.org (Barry)
Newsgroups: comp.lang.python
Subject: Re: Introspecting the variable bound to a function argument
Date: Wed, 22 Feb 2023 17:21:49 +0000
Lines: 39
Message-ID: <mailman.1918.1677086525.20444.python-list@python.org>
References: <E94BABCB-5C96-4ACF-B1B6-4E17DD2A07B8@barrys-emacs.org>
Mime-Version: 1.0 (1.0)
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de syqO5ki8O+t+kN6/S0cuewsi8KhDJtK0rFpcUqvxLkFA==
Return-Path: <barry@barrys-emacs.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'def':
0.04; 'traceback': 0.04; 'variable': 0.05; 'lets': 0.07; 'cc:addr
:python-list': 0.09; 'from:addr:barry': 0.09; 'int': 0.09;
'received:217.70': 0.09; 'received:gandi.net': 0.09;
'received:mail.gandi.net': 0.09; 'string,': 0.09; 'cc:no real
name:2**0': 0.14; 'url:mailman': 0.15; 'barry': 0.16; 'from:addr
:barrys-emacs.org': 0.16; 'inspect': 0.16; 'message-id:@barrys-
emacs.org': 0.16; 'outer': 0.16; 'subject:variable': 0.16;
'\xef\xbb\xbfhello,': 0.16; 'wrote:': 0.16; 'python': 0.16; 'feb':
0.17; 'cc:addr:python.org': 0.20; 'url-ip:188.166.95.178/32':
0.25; 'url-ip:188.166.95/24': 0.25; 'url:listinfo': 0.25;
'cannot': 0.25; 'cc:2**0': 0.25; 'url-ip:188.166/16': 0.25;
'function': 0.27; 'module': 0.31; 'url-ip:188/8': 0.31; 'there':
0.33; 'could': 0.38; 'list': 0.39; 'use': 0.39; 'to.': 0.39;
'to:none': 0.60; 'e-mail': 0.61; 'email': 0.63; 'skip:b 10': 0.63;
'public': 0.63; 'campaign': 0.64; 'requirement': 0.64;
'received:217': 0.67; 'facility': 0.69; 'html': 0.80; '14:43,':
0.84; 'from.': 0.84
X-Mailer: iPad Mail (20D67)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <E94BABCB-5C96-4ACF-B1B6-4E17DD2A07B8@barrys-emacs.org>
 by: Barry - Wed, 22 Feb 2023 17:21 UTC

please do not use an email address on a public list that cannot be replied to.

> On 22 Feb 2023, at 14:43, Anton Shepelev <anton.txt@g{oogle}mail.com> wrote:
>
> Hello, all.
>
> Does Python have an instrospection facility that can
> determine to which outer variable a function argument is
> bound, e.g.:

There is no requirement for a variable to be used in the call.
It could be an an int or string, 42 “forty two”.

>
> v1 = 5;
> v2 = 5;
>
> def f(a):
> print(black_magic(a)) # or black_magic('a')
>
> f(v1) # prints: v1
> f(v2) # prints: v2

There is the traceback module that lets you find where you are called from.
Also there is the inspect module that also lets tou get at the stack in more detail.

Barry

>
> --
> () ascii ribbon campaign -- against html e-mail
> /\ www.asciiribbon.org -- against proprietary attachments
> --
> https://mail.python.org/mailman/listinfo/python-list

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor