安徽合肥网站建设,网站建设制作的规划方案,ui设计去什么公司好,上海最新新闻在python中os是一个非常常用的模块#xff0c;下面是对os中方法的总结(实验为Mac环境)1 . os.name #xff1a;输出字符串指示使用的平台#xff0c;windows是nt, linux/unix/mac是posix os.nameposix2 . os.getcwd() :获取当前目录 …在python中os是一个非常常用的模块下面是对os中方法的总结(实验为Mac环境)1 . os.name 输出字符串指示使用的平台windows是nt, linux/unix/mac是posix os.nameposix2 . os.getcwd() :获取当前目录 os.getcwd()/Users/tp3 . os.system() :执行一条shell os.system(mkdir tt)04 . os.listdir( path ) :返回指定path下的所有文件名和目录名(可以看到刚才创建的tt文件) os.listdir(os.getcwd() )[.AB64CF89, .android, .bash_history, .bash_profile, .bash_profile.pysave, .CF89AA64, .CFUserTextEncoding, .config, .DS_Store, .local, .matplotlib, .mysql_history, .rediscli_history, .rnd, .ssh, .subversion, .Trash, .vim, .viminfo, .vimrc, Desktop, Documents, Downloads, dump.rdb, Library, Movies, Music, Pictures, Public, PycharmProjects, test, tt, workspace]5 . os.remove( file ) :删除文件6 . os.removedirs( path ) :删除文件夹 strPath os.getcwd() /tt print strPath/Users/heshan/tt os.removedirs(strPath)7 . os.sep : 可取带操作系统特定的路径分割符8 . os.linesep :当前平台的行分割符 os.sep/ os.linesep\n 9 . os.path.exists( path ) :检验目录path是否存在10 . os.path.isdir( path ) :path是否是目录10 . os.path.isfile( file ): file是否是文件 os.path.isdir(os.getcwd())True os.path.isfile(os.getcwd())False os.path.exists(os.getcwd())True11 . os.path.getsize( file ): 获取文件大小12 . os.path.splitext( file ): 分离文件后缀名13 . os.path.split( file ): 分离文件名和目录14 . os.path.join( path file ): 连接目录和文件名15 . os.path.dirname( file ): 返回文件目录 os.path.getsize(os.getcwd())1156 os.path.splitext(os.getcwd())(/Users/tp, ) os.path.split(os.getcwd())(/Users, heshan) os.path.join(os.getcwd(),test.in)/Users/heshan/test.in os.path.dirname(os.getcwd())/Users