import app as a print("Hellp app second ") a.print_hello() print(__name__)
import app print("Hello from second_app.") app.print_hello()
#app.py def print_hello(): print("hello from app.") print(__name__) if __name__ == '__main__': print_hello() #second_app.py import app #Since app.py was imported, __name__ keeps the module name "app". #All other execution during import is block by the if __name__ == "__main__" statement print("hello from second_app.") app.print_hello() #referencing the function in the imported file. #console python app.py __main__ hello from app. python second_app.py app hello from second_app. hello from app.
from app import print_hello print("Hello from second") print_hello()
def test_print_hello(caplog): caplog.set_level(logging.INFO) print_hello() for record in caplog.records: assert record.levelname == "INFO" assert record.message == "Hello World"