python: i have an error while trying this on my mac using IDLE on mac or terminal
<p>i want to see some info and get info about my os with python as in my tutorial but actually can't run this code:</p>

<pre><code>import os
F = os.popen('dir') 
</code></pre>

<p>and this :</p>

<pre><code>F.readline()
' Volume in drive C has no label.\n'
F = os.popen('dir')               # Read by sized blocks
F.read(50)
' Volume in drive C has no label.\n Volume Serial Nu'

os.popen('dir').readlines()[0]    # Read all lines: index
' Volume in drive C has no label.\n'
os.popen('dir').read()[:50]       # Read all at once: slice
' Volume in drive C has no label.\n Volume Serial Nu'

for line in os.popen('dir'):      # File line iterator loop
...     print(line.rstrip())
</code></pre>

<p>this is the the error for the first on terminal, (on IDLE it return just an '</p>

<p>f = open('dir')
   Traceback (most recent call last):
   File "", line 1, in 
   FileNotFoundError: [Errno 2] No such file or directory: 'dir'</p>

<p>I know on mac it should be different but how? to get the same result
using macOS sierra.</p>

<p><code>open</code> and <code>os.popen</code> <em>are entirely different</em><sup>*</sup>. </p>

<p>The first one just opens a file (by default <em>for reading</em>), but the second one runs a command in your shell and gives you the ability to communicate with it (e.g. get the output). </p>

<p>So, given that <code>open</code> opens the file for reading when you supply only the file's name, if such a file doesn't exist, it raises an error, which is the case here. </p>

<p><code>os.popen</code> executes the given command on your computer as if you typed it in the terminal. </p>

<hr>

<p><sup>* There exists another function with a similar name: <code>os.open</code>, which is, again, <a href="http://stackoverflow.com/questions/7219511/whats-the-difference-between-io-open-and-os-open-on-python">different</a> from the ones mentioned earlier.</sup></p>

python osx