In a default Flask app, PyCharm generates the following code:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run()
In almost all of the tutorials I'm following (socketio, right now), It wants me to add initialization code within the if statement (like so):
if __name__ == '__main__':
app = socketio.Middleware(sio, app)
eventlet.wsgi.server(eventlet.listen(('', 8000)), app)
QUESTION
__name__
seems to always equal app
Which means __name__
does not equal __main__
and therefore will not enter this if statement. What exactly is the purpose of this if statement? Is it PyCharm specific or maybe some way to start the application in production? If so, how does production automatically set the __name__
to __main__
?
Trying to figure out where these variables come from so I can figure out proper placement of code (ie: socketio).
Reference: https://python-socketio.readthedocs.io/en/latest/