【发布时间】:2014-12-19 13:19:29
【问题描述】:
我写了一个小python脚本,但是bash不会执行它:
#!/usr/bin/python
'''
Created on Dec 19, 2014
'''
import subprocess
if __name__ == '__main__':
p = subprocess.Popen('df -h', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out,err = p.communicate()
for o in out.splitlines():
if('rootfs' in o):
print o.split()[3]
当我运行./te.py 时,bash 给了我一个错误:
-bash: ./te.py: /usr/bin/python^M: bad interpreter: No such file or directory
有什么问题?
【问题讨论】:
-
那个
^M表示你的行尾有问题 -
您使用的是什么版本的 Python?如果您使用的是 Python 3.x,它可能是
#!/usr/bin/python3 -
Python 2,因为 print 周围没有括号。
-
尝试在 vi 或 vim 中编辑你的行(创建新的行尾)
-
我用 nano 编辑这个脚本 ...
标签: python python-2.x shebang