Esempio n. 1
0
import app as a

print("Hellp app second ")

a.print_hello()

print(__name__)
Esempio n. 2
0
import app

print("Hello from second_app.")
app.print_hello()



Esempio n. 3
0
#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.
Esempio n. 4
0
from app import print_hello

print("Hello from second")
print_hello()
Esempio n. 5
0
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"