This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from extensions import socketio | |
def create_app(): | |
app = Flask(__name__) | |
# other initializations and configurations | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask_socketio import SocketIO | |
socketio = SocketIO(async_mode="gevent", cors_allowed_origins='some url') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using the % operator | |
proglang = "Python" | |
print('The Zen of %s' % proglang) | |
# Using the .format() method | |
my_str = 'The Zen of {}' | |
print(my_str.format(proglang)) | |
# Using f-strings | |
print(f"The Zen of {proglang}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bad | |
capitals = dict(india='delhi', netherlands='amsterdam') | |
try: | |
captial = capitals['kenya'] | |
except: | |
print("What is this error") | |
# Good | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bad | |
try: | |
mylist = get_items() | |
exception Exception as e: | |
pass | |
return mylist | |
# Good | |
import logging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if i>0: return sqrt(i) | |
elif i==0: return 0 | |
else: return 1j * sqrt(-i) | |
# Versus | |
if i > 0: | |
return sqrt(i) | |
elif i == 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in xrange(5): | |
print i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
counter = 0 | |
while counter < 5: | |
print counter | |
counter += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# c,a,b,d are some random variables | |
c = a and b or d | |
# or | |
if a: | |
c = b | |
else: | |
c = d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .. import some_module | |
# or | |
from foo.bar import some_module | |
# another example | |
from foo.bar.some_module import * | |
# or | |
from foo.bar.some_module import specific_variable |