import flask
import random
app=flask.Flask()
@app.route('/')
def random_redir():
with open('urls.txt') as of:
return flask.redirect(random.choice(of.readlines())) import flask
import random
app=flask.Flask()
@app.route('/')
def random_redir():
with open('urls.txt') as of:
return flask.redirect(random.choice(of.readlines()))this is false
> two orders of magnitude faster
incorrect
> doesn't let your users DOS you by triggering huge file reads on each request.
I understood what you were trying to do on your first reply – "Prolly don't want to read the file on every request though" – no need to repeat yourself.
plese remember:
1. it's pseudo code, the optimisation is superfluous
2. it never ran, the optimisation is useless