I am newbie to python,
Q1 : I am wondering, Why print statement is executing multiple times, even though I called school1.print_name()
only once?
Q2 : What is purpose of __init__.py
that is being created when creating a new
package?
Q3 : What difference does it make creating an object from otherfile.py
and
__init__.py
?
(Note: I debugged the code from otherfile.py and init.py, where the script is not terminating after calling the school1.print_name(), but it is running again from the start of script)
SameFile.py
class School:
def __init__(self, name):
self.name = name
def print_name(self):
print("School name is : " + self.name)
school1 = School("DPS") # 1
school1.print_name()` # 2
# These 1 and 2 lines are removed from this file when running from otherfile.py and __init__.py
o/p :
School name is : DPS
OtherFile.py
import School
school1 = School("DPS")
school1.print_name()
o/p :
School name is : DPS
School name is : DPS #why did it print second time
__init__.py
import School
school1 = School("DPS")
school1.print_name()
o/p :
School name is : DPS
School name is : DPS #why did it print second time