Computer Science
A function checkMain() defined in module Allchecks.py is being used in two different programs. In program 1 as Allchecks.checkMain(3, 'A')
and in program 2 as checkMain(4, 'Z')
. Why are these two function-call statements different from one another when the function being invoked is just the same ?
Python Libraries
1 Like
Answer
Allchecks.checkMain(3, 'A')
and checkMain(4, 'Z')
these two function-call statements are different from one another when the function being invoked is same because in Allchecks.checkMain(3, 'A')
statement, Allchecks.py module is imported using import Allchecks
import statement in a new namespace created with the same name as that of module name and hence they are called by dot notation whereas in checkMain(4, 'Z')
statement Allchecks.py module is imported using from Allchecks import checkMain
import statement in the current namespace and hence its module name is not specified along with the function name.
Answered By
2 Likes
Related Questions
Explain the difference between
import <module>
andfrom <module> import
statements, with examples.Create module tempConversion.py as given in Fig. 4.2 in the chapter. If you invoke the module with two different types of import statements, how would the function call statement for imported module's functions be affected ?
Given below is semi-complete code of a module basic.py :
# """...............""" def square(x): """...............""" return mul(x, x) ...............mul(x, y): """...............""" return x * y def div(x, y): """...............""" return float(x)/y ...............fdiv(x, y)............... """...............""" ...............x//y def floordiv(x, y)............... ...............fdiv(x, y)
Complete the code. Save it as a module.
After importing the above module, some of its functions are executed as per following statements. Find errors, if any:
(a) square(print 3)
(b) basic.div()
(c) basic.floordiv(7.0, 7)
(d) div(100, 0)
(e) basic.mul(3, 5)
(f) print(basic.square(3.5))
(g) z = basic.div(13, 3)