Change the search path after importing

A school shop has two different files named pricing.py. Their complete contents are shown below.


File /class/shop/pricing.py


Python
UNIT_PRICE = 275


File /class/shared/pricing.py


Python
UNIT_PRICE = 240


Both prices are in cents per notebook. The module search path is the ordered list of folders Python searches to locate a module. Here, sys.path.insert(0, folder) places the specified folder at the beginning of that list.


The following program runs once in a fresh Python interpreter. Neither file has previously been imported, both folders are accessible, and no other pricing module takes precedence. The program does not reload modules or remove previously loaded modules.


Python
import sys

sys.path.insert(0, "/class/shared")
sys.path.insert(0, "/class/shop")
import pricing

first_total = 8 * pricing.UNIT_PRICE

sys.path.insert(0, "/class/shared")
import pricing as later_pricing

second_total = 12 * later_pricing.UNIT_PRICE


Find first_total and second_total. Enter each total in cents, to zero decimal places.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Modules and import Questions: