开发者

Problem about python import with error [duplicate]

开发者 https://www.devze.com 2023-01-03 07:02 出处:网络
This question already has answers here: Getting Python error "from: can't read /var/mail/Bio"
This question already has answers here: Getting Python error "from: can't read /var/mail/Bio" (7 answers) Closed 7 months ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消