Problem about python import with error [duplicate]
I have write a small python module with one class and two functions. The skeleton of the module is as following:
#file name: test_module.py
class TestClass:
@classmethod
def method1(cls, param1):
#to do something
pass
def __init__(self, param1):
#to do something
...
def fun1(*params):
#to do something
...
def fun2(*params):
#to do something
...
Another py file is a small script which im开发者_如何学JAVAports function and class from the module, as following:
import sys
from test_module import TestClass, fun1, fun2
def main(sys_argv):
li = range(5)
inst1 = TestClass(li)
fun1(inst1)
fun2(inst1)
return
if __name__ == "__main__":
main(sys.argv)
But when I execute the script, it is broken with following message:
- from: can't read /var/mail/test_module
./script.py: line 4: syntax error near unexpected token `('
./script.py: line 4: `def
main(sys_argv):'
I am not sure what the problem is. Is it a problem with import? But when I try to import the module in ipython, everything is just ok.
Add a proper shebang line to your "small script". It's being interpreted as a shell script.
精彩评论