1

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.

0

2 Answers 2

3

Your quotes look weird, use shift-2 and nothing else, i.e. a "

ascii 34, hex 22, octal 042

If you are using vim as your editor, you can check value under cursor using ga

Sign up to request clarification or add additional context in comments.

2 Comments

shift-2 is only " on some keyboards. On US keyboards shift-2 is @ and the " is over next to the return key.
Yea yea rub it in. That's why I posted the ascii-values (2 out of 3 wasn't that bad) ;-)
2

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 .

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.