Answers for "init main python"

9

python if __main__

#Add this code to run a support module on its own.
#Great for running quick tests.

if __name__ == "__main__":
	function_that_starts_the_module_to_run_on_its_own() 
    #or
    test_function_included_in_module()
Posted by: Guest on July-02-2020
8

if __name__ == '__main__'

if __name__ == "__main__":
Posted by: Guest on June-16-2020
-1

explained if name main python

# Suppose this is foo.py.

print("before import")
import math

print("before functionA")
def functionA():
    print("Function A")

print("before functionB")
def functionB():
    print("Function B {}".format(math.sqrt(100)))

print("before __name__ guard")
if __name__ == '__main__':
    functionA()
    functionB()
print("after __name__ guard")
Posted by: Guest on March-08-2020
1

__init__ python

class A(object):
    def __init__(self):
        self.x = 'Hello'

    def method_a(self, foo):
        print self.x + ' ' + foo
Posted by: Guest on May-16-2021

Python Answers by Framework

Browse Popular Code Answers by Language