28. When the script execution module
! ! ! ! Note that this is a two documents is student.py and app3.py
student.py
name = "Song Ke" NAME_LIST = [ " Joe Smith " , " John Doe " , " Wang Wu " ] def who_am_i(myName): print(f'my name is : {myName}') class Student: def __init__(self, name, age, sex): self.__name = name self.__age = age self.__sex = sex def who_am_i(self): print(f'i am a student , {self.__name}, {self.__age}, {self.__sex}')
run results:
Now add in student.py
print(name) print(name_list)
run results:
Then open app3.py input
import student
run of results app3.py
To student.py can run out, app.py output is empty can be added as follows student.py:
if (__name__ == "__main__"):
Again run student.py:
Then run app3.py
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
app3.py input
import student print (dir ()) print (you (student)) print(__name__) print(student.__name__)
run results: there are two __name__ then print out __name__ result app3.py this is __main__ ||||| student.py is a student
Back to student.py input
print(__name__)
run result: The student is __main__