SyntaxError: invalid syntax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • quocduan

    SyntaxError: invalid syntax

    I am learning Python, and i get an error in following:

    i already create a module hello.py in following:

    def print_func(par) :
    print par
    return


    then, i open new window of Python, and type import commands:
    import hello.py
    and just occur errors:

    >>> import hello.py

    Traceback (most recent call last):
    File "<pyshell#0 >", line 1, in <module>
    import hello.py
    File "C:\Python27\li b\hello.py", line 1
    Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32
    ^
    SyntaxError: invalid syntax
    >>>
    the question is what error, how i can fix it?
    thanks!
    Last edited by bvdet; Oct 4 '10, 05:53 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    The import statement should look like this:import hello. If you include the extension, python will try to find a module named "py".

    Apparently on line 1 you have the string "Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32". Remove that string or comment it out and try again.
    Last edited by bvdet; Oct 5 '10, 01:15 AM.

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

      #3
      Info on the shebang (first line) and import.

      Comment

      Working...