Search code examples
pythoncommand-linenameerror

NameError: name 'ls' is not defined


I am running Windows 7 and just installed Python 2.7.4 and all I get are SyntaxError:'s. For example when I type:

>>>ls   

I get

Traceback (most recent call last):
  file "<stdin>", line 1, in <module>
NameError: name 'ls' is not defined.

I am new to Python and have no idea what the problem is. Math calculations work as well as code seems to work. It's just commands like cd, ls, sudo apt-get update (and upgrade). Any guidance would be appreciated.


Solution

  • The Root of my problem was that I was not asking the right question. I was trying to run scripts in the interactive-mode and entering 'ls' and 'dir' to see where I was in the directory. With everyone's guidance I finally found the part in the Docs about Executable Python Scripts that said Windows automatically associates the 'py' extension with python.exe. here. Then it all came together in my head. I had associated the 'py' extension with my editor instead of python and that I should have been at the Windows command prompt. Thanks for everyone's help and quick responses.