title: Count the total number of words from stdin
body: <p>I have to read a text file name (the text file is already on my computer), open it, read it, and print the total number of words.</p>
  <p>Here is what I've tried so far:</p>
  <pre class="lang-py prettyprint-override"><code>import sys
  
  file = sys.stdin
      
  with open(file) as f: # also tried using open(file, 'r', encoding='utf-8')
      data = f.readlines()
      words = data.split()
      
      no_of_words = 0
      for word in words:
          no_of_words += 1
          print(no_of_words)
  </code></pre>
  <p>But when I try to run it, it shows the following error:</p>
  <pre class="lang-py prettyprint-override"><code>&quot;with open(file) as f:
  TypeError: expected str, bytes or os.PathLike object, not TextIOWrapper&quot;
  </code></pre>