0

I have this code:

#!/usr/local/bin/python
"""

USAGE:

    apache_logs.py 

"""

import sys
import os


if __name__ == "__main__":
    if not len(sys.argv) > 1:
        print __doc__
        sys.exit(1)
    infile_name = sys.argv[1]

I get an error that says

Tue Jul 21{stevenhirsch@steven-hirschs-macbook-pro-2}/projects/python:-->./apache_logs.py 
  File "./apache_logs.py", line 17
    print __doc__
                ^
SyntaxError: invalid syntax

Why? The documentation I've read all seems to suggest it should work.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
ennuikiller
  • 46,381
  • 14
  • 112
  • 137

1 Answers1

5

What version of Python do you have? In Python 3, print was changed to work like a function rather than a statement, i.e. print('Hello World') instead of print 'Hello World'

I can recommend you to keep using Python 2.6 unless you're doing some brand new production development. Python 3 is still pretty new.

Blixt
  • 49,547
  • 13
  • 120
  • 153
  • Right, no one should be using Python 3.x yet unless they have a really good reason. – aehlke Jul 21 '09 at 21:48
  • 1
    It's fine to use Python 3.x for small hobby projects, as long as you're aware that most of the 3rd-party Python libraries haven't been ported yet. – Marius Gedminas Jul 21 '09 at 23:12
  • Wahnfrieden, why should 'no one' use Python 3.0. If it's library support, you've got a serious chicken and the egg problem. If 'no one' should use it then no libraries will be ported. I'd recommend using Python 3 if you accept the library limits, if you don't, then you should use 2.6. – Paul Whitehurst Jul 21 '09 at 23:51
  • Developing a Python library is a "really good reason" to be using Python 3.x, so my point stands. Basically, if you have to ask, then Python 3.x isn't for you, yet, but maybe in a year or two. For learners, 2.6 already has some important 3.0 features backported to it, so it's a much better starting place. – aehlke Jul 22 '09 at 14:39