CS FundamentalsVery hardProduct-company placement · Python

A Python app keeps a shared Settings object at module level in settings.py as a singleton. Most code imports it as app.settings, but one script, run with a different sys.path, imports it as plain settings. What happens?

  1. A. Python loads the module twice under two names, giving two separate Settings objects
  2. B. Python detects the same file and returns the one cached module
  3. C. The second import raises ImportError because the module is already loaded
  4. D. Both names share state, because module objects are always looked up by file path

Correct answer: A. Python loads the module twice under two names, giving two separate Settings objects

Modules are cached in sys.modules by import name, so one file imported as 'app.settings' and as 'settings' is executed twice and holds two independent objects. Module-level singletons are only one per name per interpreter.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic