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?
- A. Python loads the module twice under two names, giving two separate Settings objects
- B. Python detects the same file and returns the one cached module
- C. The second import raises ImportError because the module is already loaded
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- What does this code print? python class Count: def init(s, n): s.i = 0; s.n = n def iter(s): return s def next(s): if s.i >= s.n: raise…
- In a strictly layered system, 80% of requests pass through the business and service layers unchanged, which merely forward each call to…
- How many of these are Twelve-Factor App recommendations? 1. Write logs as an event stream to stdout and let the environment route them. 2…
- Before refactoring a legacy pricing module with no tests, a developer records its current outputs for many inputs, including results she…
- A new filter must be added to a 400-line untested method. Instead of editing the method's logic, the developer writes the filter as a new…
- A quality-attribute scenario reads: 'During peak sale traffic, a shopper's search request is answered by the catalogue service within 2 s…