Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I can't run programs with IDLE or any files saved with IDLE. I get a syntax error. I was just testing it out with print "Hello World". This is the message I am receiving

File "p.py", line 1
    Python 2.7.3 (default, Sep 26 2013, 16:38:10) 
             ^
SyntaxError: invalid syntax

Why is it reading the title? How can I fix this?

share|improve this question

closed as off-topic by RolandiXor Jan 13 at 20:49

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – RolandiXor
If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

1 Answer 1

up vote 1 down vote accepted

You have put the interactive interpreter's header into the file. This is not required, and wont work.

E.g.: You open a python shell and do this:

Python 2.7.4 (default, Sep 26 2013, 03:20:26) 
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "Hello world!"
Hello world!
>>> 

The above is made up of:

  • The standard header, this is printed each time you start the shell:

    Python 2.7.4 (default, Sep 26 2013, 03:20:26) 
    [GCC 4.7.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    
  • The an entered command: To use this in a file, you remove the >>> prefix.

    >>> print "Hello world!"
    
  • The printed output: This is distinct in that it doesn't start with >>>.

    Hello world!
    
  • A new prompt, for you to type in:

    >>> 
    

So, if you were to make a file which runs the commands as you did in the above interactive session, you would simply use:

print "Hello world!"
share|improve this answer
    
OK cool thanks a lot. –  Revan Jan 12 at 6:45
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.