Python Forum
module functions and data references
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
module functions and data references
#7
i have modified the code to show some more information.

the module callers.py:
from __future__ import division, print_function

from_callers_which_namespace_will_this_assignment_be_put_in = 'from callers which namespace will this assignment be put in ?'

def a():
    print('this is a')
    return

def b():
    print('this is b')
    return

def c():
    print('this is c')
    return

def d():
    print('this is d')
    return

def x():
    print('this is x')
    
    from_x_which_namespace_will_this_assignment_be_put_in = 'from x which namespace will this assignment be put in ?'[:-2]

    print('in x locals keys =',repr(locals().keys()))
    print('in x globals keys =',repr(globals().keys()))

    a()
    b()
    return

def y():
    print('this is y')
    c()
    d()
    return
the script:
from __future__ import division, print_function

from callers import x, y

which_namespace_will_this_assignment_be_put_in = 'which namespace will this assignment be put in ?'[:-2]

print('locals keys =',repr(locals().keys()))
print('globals keys =',repr(globals().keys()))

x()
print('foobar')
y()
and the new output:
Output:
locals keys = ['division', 'which_namespace_will_this_assignment_be_put_in', '__builtins__', '__file__', '__package__', 'x', 'y', '__name__', '__doc__', 'print_function'] globals keys = ['division', 'which_namespace_will_this_assignment_be_put_in', '__builtins__', '__file__', '__package__', 'x', 'y', '__name__', '__doc__', 'print_function'] this is x in x locals keys = ['from_x_which_namespace_will_this_assignment_be_put_in'] in x globals keys = ['a', 'division', 'c', 'b', 'd', '__builtins__', '__file__', '__package__', 'from_callers_which_namespace_will_this_assignment_be_put_in', 'x', 'y', '__name__', '__doc__', 'print_function'] this is a this is b foobar this is y this is c this is d
when the script is running it has one namespace referenced both as local and as global.  when i think about it, the script just had code not in a function so there was only one context, anyway.  but in function x we see where its own symbols are referenced from.  and we can see that division and print_function are visible.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
module functions and data references - by Skaperen - Jul-29-2017, 03:15 AM
RE: module functions and data references - by buran - Jul-29-2017, 05:07 AM
RE: module functions and data references - by Skaperen - Jul-30-2017, 04:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  get data from 2 async functions korenron 0 1,243 Sep-22-2021, 08:39 AM
Last Post: korenron
  Environment seems to keep losing references spacedog 2 1,922 Apr-23-2021, 07:36 PM
Last Post: spacedog
  Taking serial data to perform key.press functions ausbollinger13 1 2,349 Sep-04-2020, 10:26 PM
Last Post: bowlofred
  module to store functions/variables and how to call them? mstichler 3 2,444 Jun-03-2020, 06:49 PM
Last Post: mstichler
  assignments of function references Skaperen 3 2,406 Aug-15-2019, 11:12 AM
Last Post: fishhook
  How to find functions or methods in a module? deepakdeshp 8 4,302 May-23-2019, 09:36 AM
Last Post: DeaD_EyE
  calling os functions not in module os Skaperen 2 2,658 Nov-10-2018, 01:54 AM
Last Post: Skaperen
  Python what should be name of the module for managing data of users ? harun2525 3 3,450 Dec-06-2017, 06:11 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020