Problem about python import with error

Posted by xiao on Stack Overflow See other posts from Stack Overflow or by xiao
Published on 2010-06-11T07:38:52Z Indexed on 2010/06/11 7:43 UTC
Read the original article Hit count: 287

Filed under:
|

Hello, 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 imports 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:

  • ./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.

© Stack Overflow or respective owner

Related posts about python

Related posts about import