I Have a written a small python code with intention of getting my system information and disk size. I am using subprocess module here.
[root@localhost code]# cat pysys.py
#!/usr/bin/python
import subprocess;
def sysinfo():
subprocess.call(“uname –a”,shell=True)
def diskinfo():
subprocess.call(“df –h”,shell=True)
def main():
sysinfo()
diskinfo()
main()
When ever I am trying to execute , I am getting the error as
[root@localhost code]# python pysys.py
File "pysys.py", line 5
SyntaxError: Non-ASCII character '\xe2' in file pysys.py on line 5, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
[root@localhost code]#
EDIT:
[root@localhost code]# cat pysys.py
#!/usr/bin/python
import subprocess;
def sysinfo():
subprocess.call("uname –a",shell=True)
def diskinfo():
subprocess.call("df –h",shell=True)
def main():
sysinfo()
diskinfo()
main()
[root@localhost code]# python pysys.py
File "pysys.py", line 5
SyntaxError: Non-ASCII character '\xe2' in file pysys.py on line 5, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
[root@localhost code]#
Am I missing anything ? Please let me know.
Thank you.
Your quotes look weird, use shift-2 and nothing else, ie a "
ascii 34, hex 22, octal 042
If you are using vim as your editor, you can check value under cursor using ga
It seems you are using non-ASCII character.( –
/ '
). It usually happens when you copy content from somewhere.
So modify your code as below:
#!/usr/bin/python
import subprocess;
def sysinfo():
subprocess.call("uname -a",shell=True)
def diskinfo():
subprocess.call("df -h",shell=True)
def main():
sysinfo()
diskinfo()
main()
The difference is just -
. You are using –
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.