471,092 Members | 1,158 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

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

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\lib\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?
Oct 4 '10 #1
2 1323
2,851 Expert Mod 2GB
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.
Oct 4 '10 #2
626 Expert 512MB
Info on the shebang (first line) and import.
Oct 6 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Bradley Kite | last post: by
reply views Thread by Mark Phanides | last post: by
5 posts views Thread by DIBS | last post: by
2 posts views Thread by py | last post: by
reply views Thread by cesare | last post: by
10 posts views Thread by ronrsr | last post: by
4 posts views Thread by Kai Kuehne | last post: by
7 posts views Thread by alf | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.