Answers for "how to check if user is using main file or importing the file and using in python"

1

how to check if user is using main file or importing the file and using in python

#in another file
from first_program import calculate_adding
number1 = int(input("Number 1:- "))
number2 = int(input("Number 2:- "))
print(calculate_adding(number1,number2))
#output
'''
You are using me after importing
Number 1:- 90
Number 2:- 90
180
'''
Posted by: Guest on October-02-2021
1

how to check if user is using main file or importing the file and using in python

def calculate_adding(num1,num2):
    return num1 + num2
if __name__ == '__main__':
    print("Hi you are using editor not importing")
    print(calculate_adding(90,10))
if __name__ != '__main__':
    print("You are importing me and using me")
#output
'''
Hi you are using editor not importing
100
'''
Posted by: Guest on October-02-2021

Code answers related to "how to check if user is using main file or importing the file and using in python"

Python Answers by Framework

Browse Popular Code Answers by Language