Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
'''
Comment

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
'''
Comment

PREVIOUS NEXT
Code Example
Python :: pip install dal 
Python :: django admin order by 
Python :: pandas series to list 
Python :: how to use tensorboard 
Python :: reverse order np array 
Python :: django check if user is staff in template 
Python :: one hot encoder python 
Python :: python open dicom file 
Python :: python pip fix 
Python :: random choice dictionary python 
Python :: remove rows or columns with NaN value 
Python :: Get value from TextCtrl wxpython 
Python :: ROLL D6 
Python :: how to change dtype object to int 
Python :: python image black and white 
Python :: redirect django 
Python :: django login redirect 
Python :: write geopands into postgres python 
Python :: python code to wait 
Python :: write specific columns to csv pandas 
Python :: how to add space before capital letter in python 
Python :: python strip multiple characters 
Python :: goal parser 
Python :: filter rows pandas 
Python :: python format float 
Python :: how to add headings to data in pandas 
Python :: pass user to serializer django rest framework 
Python :: python select random subset from numpy array 
Python :: flask hello world 
Python :: pandas merge dataframes from a list 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =