• Introspecting the variable bound to a function argument

    From Anton Shepelev@21:1/5 to All on Wed Feb 22 13:32:39 2023
    Hello, all.

    Does Python have an instrospection facility that can
    determine to which outer variable a function argument is
    bound, e.g.:

    v1 = 5;
    v2 = 5;

    def f(a):
    print(black_magic(a)) # or black_magic('a')

    f(v1) # prints: v1
    f(v2) # prints: v2

    --
    () ascii ribbon campaign -- against html e-mail
    /\ www.asciiribbon.org -- against proprietary attachments

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Barry@21:1/5 to All on Wed Feb 22 17:21:49 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hen Hanna@21:1/5 to Anton Shepelev on Wed Feb 22 12:12:10 2023
    On Wednesday, February 22, 2023 at 2:32:57 AM UTC-8, Anton Shepelev wrote:
    Hello, all.

    Does Python have an instrospection facility that can
    determine to which outer variable a function argument is
    bound, e.g.:

    v1 = 5;
    v2 = 5;


    do some Python coders like to end lines with ; ?



    def f(a):
    print(black_magic(a)) # or black_magic('a')

    f(v1) # prints: v1
    f(v2) # prints: v2


    the term [call by name] suggests this should be possible.


    30 years ago... i used to think about this type of thing A LOT ---
    ------- CBR, CBV, CBN, (call by value), (call by name).... etc.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Hen Hanna on Wed Feb 22 19:24:02 2023
    On 2/22/2023 3:12 PM, Hen Hanna wrote:
    On Wednesday, February 22, 2023 at 2:32:57 AM UTC-8, Anton Shepelev wrote:
    Hello, all.

    Does Python have an instrospection facility that can
    determine to which outer variable a function argument is
    bound, e.g.:

    v1 = 5;
    v2 = 5;


    do some Python coders like to end lines with ; ?

    Very few, probably. It's not harmful but adds unnecessary visual clutter.


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


    the term [call by name] suggests this should be possible.


    30 years ago... i used to think about this type of thing A LOT ---
    ------- CBR, CBV, CBN, (call by value), (call by name).... etc.


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Greg Ewing@21:1/5 to Hen Hanna on Thu Feb 23 19:15:59 2023
    On 23/02/23 9:12 am, Hen Hanna wrote:
    On Wednesday, February 22, 2023 at 2:32:57 AM UTC-8, Anton Shepelev wrote:
    def f(a):
    print(black_magic(a)) # or black_magic('a') >>
    f(v1) # prints: v1
    f(v2) # prints: v2


    the term [call by name] suggests this should be possible.

    But Python doesn't use call-by-name or anything remotely like it.

    (Even if it did, the word "name" in that context doesn't mean
    what it sounds like it means. The Algol docs used some words in
    weird ways.)

    --
    Greg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)