''' os模块 os.name nt-->windows;posix-->linux os.system(cmd) 没有返回值,纯粹执行 re = os.popen(cmd) 有返回值 re.read() ''' import os # 判断系统nt--windows posix--unix print(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:") #列出当前目录,ls os.chdir("D:") #改变目录,cd print(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"))
python 笔记 之 os模块
猜你喜欢
转载自my.oschina.net/u/3824134/blog/1801276
今日推荐
周排行