'''os模块os.name nt-->windows;posix-->linuxos.system(cmd) 没有返回值,纯粹执行re = os.popen(cmd) 有返回值re.read()'''import os# 判断系统nt--windows posix--unixprint(os.name)if os.name =="nt": cmd = "ipconfig"elif os.name == "posix": cmd = "ifconfig"os.system(cmd)os.system(cmd) # 执行系统命名,没有返回值re = os.popen(cmd)re.read() #可以对re进行处理os.listdir("C:") #列出当前目录,lsos.chdir("D:") #改变目录,cdprint(os.listdir())print(os.getcwd()) #当前路径,pwd# os.mkdir("test") #创建目录# os.remove("1.log") # 删除文件# os.rmdir("test") # 删除目录# os.rename("demoddd.py","demoTest.py") #改名print(os.linesep) #换行#windows 换行符\n\r linux换行符\n mac \r ?'''(1)在微软的MS-DOS和Windows中,使用“回车CR('\r')”和“换行LF('\n')”两个字符作为换行符;(2)Windows系统里面,每行结尾是 回车+换行(CR+LF),即“\r\n”;(3)Unix系统里,每行结尾只有 换行CR,即“\n”;(4)Mac系统里,每行结尾是 回车CR 即'\r'。'''# 目录不存在,才创建if not os.path.exists("test"): os.mkdir("test")print(os.pardir)print(os.path.abspath("./"))print(os.path.split("V:\chenyuan\python\studey"))