Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python if main

# if __name__ == '__main__' checks if a file is imported as a module or not.
# example: 
def main():
    print('Hello World')
    
if __name__ == '__main__':
    # This code won't run if this file is imported.
    main()
Comment

if main python

# Python program to execute
# main directly
print ("Always executed")
 
if __name__ == "__main__":
    print ("Executed when invoked directly")
else:
    print ("Executed when imported")
Comment

PREVIOUS NEXT
Code Example
Python :: ValueError: Tz-aware datetime.datetime cannot be converted to datetime64 unless utc=True site:stackoverflow.com 
Python :: how to check python version 
Python :: installing pip 
Python :: python mkdir 
Python :: pandas get rows string in column 
Python :: how to open webcam with python 
Python :: copy to clipboard python 
Python :: pandas set options 
Python :: python get stack trace 
Python :: how to simulate a key press in python 
Python :: tkinter label border 
Python :: heroku run python manage.py migrate 
Python :: Creating an admin user in django terminal 
Python :: python loop through all folders and subfolders 
Python :: ubuntu remove python 2.7 
Python :: how to loop through dates in python 
Python :: how to check weather my model is on gpu in pytorch 
Python :: for every file in the folder do python 
Python :: list files in s3 folder python 
Python :: how to make a tkinter window 
Python :: unzip in python 
Python :: python convert number to list of digits 
Python :: how to remove integer from string in python 
Python :: translate sentences in python 
Python :: install python on windows subsystem for linux 
Python :: pandas how to get last index 
Python :: classification report scikit 
Python :: how to save python list to file 
Python :: enter key press bind tkinter 
Python :: python set cwd to file location 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =