मुझे एक फ़ंक्शन को दूसरे फ़ंक्शन के साथ एक अलग मॉड्यूल से बदलने में परेशानी हो रही है और यह मुझे पागल कर रहा है।
मान लें कि मेरे पास एक मॉड्यूल बारकोड है जो इस तरह दिखता है:
from a_package.baz import do_something_expensive
def a_function():
print do_something_expensive()
और मेरे पास एक और मॉड्यूल है जो इस तरह दिखता है:
from bar import a_function
a_function()
from a_package.baz import do_something_expensive
do_something_expensive = lambda: 'Something really cheap.'
a_function()
import a_package.baz
a_package.baz.do_something_expensive = lambda: 'Something really cheap.'
a_function()
मैं परिणाम प्राप्त करने की उम्मीद करूंगा:
Something expensive!
Something really cheap.
Something really cheap.
लेकिन इसके बजाय मुझे यह मिलता है:
Something expensive!
Something expensive!
Something expensive!
मैं क्या गलत कर रहा हूं?