python - 我的 Python 代码适用于我的 MacBook Pro,但不适用于任何其他 MacBook
问题描述
每个人。我是一个刚接触 python 的学生,我刚刚写了一个脚本,它在我的 MacBook 上运行得很好,但是每当我尝试在其他人的 MacBook 上运行它时,它都会给我一个错误消息说
SyntaxError: invalid non-printable character U+00A0.
即使我尝试在线搜索,我也不知道发生了什么,有人可以帮助我吗?
这是我的代码:
#!/usr/bin/env python3
import socket
import shutil
import psutil
import math
import MacTmp
import time
import urllib.request
import os
def check_disk_usage(disk):
"""Verifies that there's enough free space on disk"""
du = shutil.disk_usage(disk)
free = du.free / du.total * 100
return free > 20
def check_cpu_usage():
"""Verifies that there's enough unused CPU"""
usage = psutil.cpu_percent(1)
return usage < 75
def disk_amount(disk):
"""The amount of free disk"""
am = shutil.disk_usage(disk)
free = am.free / am.total * 100
return math.floor(free)
def cpu_amount():
"""The amount of cpu usage"""
used = psutil.cpu_percent(1)
return math.floor(used)
def check_localhost():
localhost = socket.gethostbyname('localhost')
return localhost == "127.0.0.1"
def internet_on():
try:
urllib.request.urlopen('http://www.google.com', timeout=2)
return True
except:
return False
size = os.get_terminal_size()
while True:
if not check_disk_usage('/'):
print("No disk for use!")
elif not check_cpu_usage():
print("You are using too much CPU")
elif not check_localhost():
print("Not the LOCALHOST")
elif internet_on() == False:
print("No Internet Connection")
elif check_localhost() and check_cpu_usage() and check_disk_usage('/'):
print("Everything is OK")
print("|Free Disk: " + str(disk_amount('/')) + "|" + "|CPU Usage: " + str(cpu_amount()) + "|" + "|CPU Temperature: " + str(MacTmp.CPU_Temp()) +"|Internet: " + str(internet_on()) + "|")
time.sleep(5)
if int(float(cpu_amount())) >= 75 or int(float(MacTmp.CPU_Temp())) >= 95:
break
elif int(size.lines > 70):
os.system('cls||clear')
print("Too much CPU is using now or Your device is very hot!")
谢谢!
解决方案
推荐阅读
- reactjs - 获取位置后如何自动导航到下一个屏幕
- reactjs - 如何最好地使用 ReactJS 中的集合更新
- r - 使用 RandomizeR 在 R 中随机化处理
- c# - 如何将sqllite连接到c#应用程序
- python - Python-telegram - 是否可以获得组中用户发送的消息数量?
- firebase-cloud-messaging - 发送到多个设备时如何处理推送通知,但其中一些失败
- .net - AspNet Core 3.1:将 IdentityUser 错误转换为 ApplicationUser
- c# - 如何在 C# 控制台应用程序中使用音效?
- vb.net - Selenium 是否需要 Chrome 驱动程序
- mongodb - 使用 Terraform 在 MongoDB Atlas 中创建第二个端点连接时出现 409(请求“冲突”)