os
import os
class OsMethod:
def __init__(self):
self.os = os
def sys_name(self):
"""
获取系统名称
:return: nt(Windows) | posix(Linux)
"""
return "Mac" if self.os.name == "posix" else "Win"
def run_cmd(self, cmd):
"""
执行 shell 命令
:param cmd: 命令
:return: 执行结果, 0(成功) | 1(失败)
"""
return self.os.popen(cmd).read()
def get_desktop(self):
"""
获取桌面路径
:return:
"""
return self.os.path.join(os.path.expanduser("~"), "Desktop")
def get_workspace(self):
"""
获取工作目录
:return:
"""
return self.os.path.dirname(__file__)
if __name__ == '__main__':
o = OsMethod()
print(o.sys_name())
res = o.get_desktop()
print(res)
res = o.get_workspace()
print(res)