Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
which namespace?
#1
when i import function foo() from a module with 2 functions, foo() and bar():

from mymodule import foo
and foo() needs to call bar(), which namespace will it get it from? local? global?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
foo() in mymodule calls bar() in mymodule. Importing foo() doesn't change that.
Reply
#3
foo() will access bar() locally within its own module namespace. This means that foo() will call bar() from the same module it was imported from, regardless of whether bar() was imported directly or not.
Reply
#4
(May-27-2024, 05:32 AM)deanhystad Wrote: foo() in mymodule calls bar() in mymodule. Importing foo() doesn't change that.
so its neither. a separate namespace where mymodule was imported is used. is there a way (for foo) to access something else in that namespace? mymodule.something_else does not seem to work.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
...or does it make everything in mymodule appear to foo() as in foo()'s local namespace? if this is true does it do the same for bar() during bar() being called?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
(May-28-2024, 12:31 AM)Skaperen Wrote: ...or does it make everything in mymodule appear to foo() as in foo()'s local namespace? if this is true does it do the same for bar() during bar() being called?
This is very difficult to understand. Can you give a concrete example with files and code?
« We can solve any problem by introducing an extra level of indirection »
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  'namespace' shorthand for function arguments? shadowphile 5 2,734 Aug-11-2021, 09:02 PM
Last Post: shadowphile
  [PyKML] Loop through all Placemarks; Remove namespace Winfried 2 3,598 Aug-28-2020, 09:24 AM
Last Post: Winfried
  Beginner question: lxml's findall in an xml namespace aecklers 0 3,015 Jan-22-2020, 10:53 AM
Last Post: aecklers
  Namespace and scope difference Uchikago 9 4,808 Jul-03-2019, 03:36 PM
Last Post: Uchikago
  global namespace of an imported function (2 Qs) Skaperen 4 3,367 Oct-09-2018, 12:30 AM
Last Post: Skaperen
  Namespace Packages jmj1970 0 3,189 Sep-30-2017, 03:13 PM
Last Post: jmj1970
  local namespace vs. global namespace Skaperen 13 10,161 Jul-02-2017, 11:30 AM
Last Post: DeaD_EyE
  python import module or namespace from namepsace variable ? harun2525 11 8,945 May-23-2017, 05:39 PM
Last Post: Larz60+
  AttributeError: 'Namespace' object has no attribute 'brokeName' kikilalongue 4 24,790 May-22-2017, 12:00 PM
Last Post: kikilalongue
  python How to import All modules from namespace harun2525 1 8,493 May-20-2017, 10:10 AM
Last Post: buran

Forum Jump:

User Panel Messages

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