Question: 1) Create two modules (empty.py and test_empty.py) files. The empty file is a shell nothing. The test_empty module is the main module. You will import
1) Create two modules (empty.py and test_empty.py) files. The empty file is a shell nothing. The test_empty module is the main module. You will import the empty file into the test_empty.py and check it out.. For the Q1_main_or_import.py, enter the following codes: ''' A module used (imported) by test_Module.py to test __name__ ( a special variable), sys.path (empty,py search path) ''' print(f'File __name__ = {__name__}') if __name__ == "__main__": print("empty is being run directly") #you can run this module (empty.py) from this py file else: print("empty is being imported") str = " I am in empty.py " # end of empty.py file For test_empty.py , enter the following codes and run it. ''' The name of the module (test_empty), which is being executed is always '__main__' Other modules are named after the filename What is import sys? what is in sys? https://docs.python.org/3/library/sys.html ''' import empty as e1 # this import import sys # sys is a system specific parameters and functions import textwrap # python build-in module used for wrapping and formatting plain text # This makes the loooong path string easier to read # __name__ is a special variable # since we are running the program from this module (as level 0 indentation) # The interpreter assigns the value __main__ to this variable __name__ to indicate the program starting point print(f'what is you nme ? {__name__}') # print __main__ print(f"run sys,path for the module search paths") print(sys.path) # shows the list if directories that python (the interpreter) will search for the module print(f'The imported file name = {e1.__name__}.py') print(f'print the str in e1: {e1.str}') # use the textwrap(variable) to reduce the string length for ease of reading sp = sorted(sys.path) dnames = ', '.join(sp) print('without textwrap.. ', dnames) print('with textwrap,, ',textwrap.fill(dnames))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
