title: How to read a file in Python Flask
body: <p>I want to implement a simple search function which when user input text in the box, it will go through the <code>json file [large.js]</code> to see if there's any matching record. If yes, the result will be shown.</p>
  
  <p>The problem is when i run the py file, there's an error <code>No such file or directory "large"</code></p>
  
  <p>Any Idea will be great. Thanks</p>
  
  <blockquote>
    <p>Below is the python code  [application.py]</p>
  </blockquote>
  
  <pre><code>from flask import Flask, render_template, request, jsonify
  app = Flask(__name__)
  WORDS = []
  with open("large", "r") as file:
      for line in file.readlines():
          WORDS.append(line.rstrip()) 
  @app.route("/")
  def index():
      return render_template("index.html")
  
  @app.route("/search")
  def search():
      q = request.args.get("q")
      words = [word for word in WORDS if word.startswith(q)]
      return jsonify(words)
  </code></pre>
  
  <blockquote>
    <p>Below is the HTML code [templates/index.html]</p>
  </blockquote>
  
  <pre><code>&lt;input type="text"&gt;
  &lt;ul&gt;&lt;/ul&gt;
  &lt;script src ="large.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  let input = document.querySelector("input")
  input.onkeyup = function (){
  let html = "";
  if (input.value){
  for (word of WORDS){
  if (word.startsWith(input.value)){
  html += "&lt;li&gt;" + word +"&lt;/li&gt;";
  }} }
  document.querySelector("ul").innerHTML = html;
  };
  &lt;/script&gt;
  </code></pre>
  
  <blockquote>
    <p>large.js file that contain the json</p>
  </blockquote>
  
  <pre><code>let WORDS = [
  "a",
  "abandon",
  "abandoned",
  "ability",
  "able"]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Bazyr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bazyr.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Ijujz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ijujz.png" alt="enter image description here"></a></p>