Reputation: 291
I just started learning python for the online course provided by 10gen education, MongoDB for developers (python), i have installed python 2.7 successfully and set the environment vars(path: C:\python27), i can open the python shell and execute the commands and stuff but when i created a python script file named (test.py) and open the command promt, navigated to the current directory C:\10gen
and when i try to run it using python test.py
it shows me an error
python: can't open file 'test.py': [Errno 2] No such file or directory
however if i execute the same obove command with .txt
extension like python test.py.txt
it works fine. my question is how would i make filename.py
execute from command line .
PS:, my script file contains simple function which iterates over an list and prints it.
Thanks in advance
Upvotes: 0
Views: 4908
Reputation: 25695
This has happened because you used Notepad and tried to save the file as (.txt) TextFile option in Save menu.
use double quotes around "file.py" or select All Files
from the dropdown(of Save as type) in the Save As Dialog box.
I recommend using EMacs for Python development. You can also start off with IDLE :-)
Upvotes: 5
Reputation: 3115
Windows has added a .txt file extension, which it is now hiding from you. Change your folder preferences to let you see file extensions and it will be there. Try using a more programmer-y text editor such as Notepad++ to avoid the problem recurring.
Upvotes: 2
Reputation: 5866
Are you using Notepad to write your python scripts? If so, by default it will add .txt to the end of your saved files. Be sure to click "Save as type All files" in the save dialog when you save your code in Notepad.
Upvotes: 2