-2

Im teaching myself python and have downloaded the newest version of python 2 and also notepad++.

I have this script in notepad++ saved as Enter_your_name.py

#Program that Welcomes user          
ask='Enter your name:'
raw_input(ask)

When I go to the python interpreter and issue the command

python Enter_your_name.py

I get a syntax error.

Is this because I am not in the correct directory?

Edit

>>>python Enter_your_name.py
File "(stdin)", line 1
python Enter_your_name.py
                     ^
SyntaxError: invalid syntax
>>>
  • 1
    FYI get rid of the semi-colons, they are not needed in Python. As far as your syntax error, please edit your post to include the full error and traceback. – Cory Kramer Feb 08 '15 at 20:39
  • You invoke the script via the command line not the interpreter. – Malik Brahimi Feb 08 '15 at 20:39
  • possible duplicate of [How to run a python script from IDLE interactive shell?](http://stackoverflow.com/questions/17247471/how-to-run-a-python-script-from-idle-interactive-shell) – Bhargav Rao Feb 08 '15 at 20:43
  • Thanks for the reference, I tried finding a similar question but couldnt. Maybe Im still a bit new to the site. I had to use execfile('helloworld.py') with the full path name. – Abid D. Alexander Feb 08 '15 at 20:50

1 Answers1

1

Open a Command Prompt or Terminal in the current directory, then type:

python Enter_your_name.py

Otherwise there is an option to run the program directly from IDLE in the drop down menus. Problem is you're getting a syntax error rather than a file not found error. This indicates your mistake in trying to execute a command from the Python shell.

Malik Brahimi
  • 16,341
  • 7
  • 39
  • 70