Python Modules (2)

Source: Internet
Author: User
Tags foxit software

1.OS Module

1 Print (OS.GETCWD ())   # get current working directory 2 os.chdir ('E:\python Practice \python35 Learning ')   # Change directory 3  Print(OS.GETCWD ())

E:\python Practice \python35 Learning \day5
E:\python Practice \PYTHON35 Study

1 Print(Os.curdir)#current directory2 Print(Os.pardir)#Parent (previous level) directory3 Print(OS.SEP)#Path delimiter4 Print(OS.PATHSEP)#File Path Separator5 Print(Os.name)#currently using platform name,win--> ' NT ',linux--> ' POSIX '6 Print(Os.environ)#environment variables (shown in dictionary)

.
..
\
;
Nt
Environ ({' processor_architecture ': ' AMD64 ', ' OS ': ' Windows_NT ', ' sessionname ': ' Console ', ' vs140comntools ': ' c:\\ Program Files (x86) \\Microsoft Visual studio\\shared\\14.0\\common7\\tools\\ ', ' logonserver ': ' \\\\DESKTOP-HU5CSPT ', ' Moz_plugin_path ': ' C:\\Program Files (x86) \\Foxit software\\foxit reader\\plugins\\ ', ' ProgramFiles (X86) ': ' c:\\ Program Files (x86) ', ' PYTHONPATH ': ' E:\\python practice \\python35 learning; d:\\python\\lib; F:\\pjproject-2.7\\tests\\pjsua ', ' pycharm_hosted ': ' 1 ', ' pythonunbuffered ': ' 1 ', ' msdevdir ': ' e:\\msdev98 ', ' _OLD_ Virtual_prompt ': ' $P $g ', ' pathext ': '. COM;. EXE;. BAT;. CMD;. VBS;. VBE;. JS;. JSE;. WSF;. WSH;. MSC ', ' systemdrive ': ' C: ', ' _old_virtual_path ': ' C:\\Program Files\\java\\jdk1.8.0\\bin; C:\\Program Files\\java\\jdk1.8.0\\jre\\bin; C:\\programdata\\oracle\\java\\javapath; C:\\Program Files (x86) \\Intel\\iCLS client\\; C:\\Program Files\\intel\\icls Client\\; C:\\Windows\\System32; C:\\Windows; C:\\windows\\system32\\wbem; c:\\windows\\system32\\windowspowershell\\v1.0\\; C:\\progRam Files (x86) \\Intel\\Intel (R) Management Engine components\\dal; C:\\Program Files\\intel\\intel (R) Management Engine components\\dal; C:\\Program Files (x86) \\Intel\\Intel (R) Management Engine components\\ipt; C:\\Program Files\\intel\\intel (R) Management Engine components\\ipt; C:\\Program Files (x86) \\NVIDIA Corporation\\physx\\common; C:\\Program Files (x86) \\Microsoft SQL server\\100\\tools\\binn\\; C:\\Program Files\\Microsoft SQL Server\\100\\tools\\binn\\; C:\\Program Files\\Microsoft SQL Server\\100\\dts\\binn\\; C:\\Windows\\System32; C:\\Windows; C:\\windows\\system32\\wbem; c:\\windows\\system32\\windowspowershell\\v1.0\\;D: \\mydownloads\\matlab\\r2016a\\runtime\\win64;d:\\ Mydownloads\\matlab\\r2016a\\bin;d:\\mydownloads\\matlab\\r2016a\\polyspace\\bin; C:\\Program Files\\Microsoft SQL Server\\130\\tools\\binn\\;D: \\Matlab install\\runtime\\win64;d:\\matlab install\\ Bin;d:\\matlab Install\\polyspace\\bin; C:\\Program Files\\mysql\\mysql Server 5.7\\bin; f:\\dsystem\\mysql-5.7.18-winx64\\bin;d:\\devlop\\mingw\\bin; C:\\users\\asus\\appdata\\local\\programs\\python\\python36;d:\\python3.5.2\\scripts\\;D: \\Python3.5.2\\;D: \ \ Anaconda3-4;d:\\anaconda3-4\\scripts;d:\\anaconda3-4\\library\\bin; E:\\tools\\winnt; E:\\msdev98\\bin; E:\\tools; C:\\users\\asus\\appdata\\local\\programs\\python\\python35; C:\\Program Files\\java\\jdk1.7.0_17\\bin; C:\\Program Files\\java\\jdk1.7.0_17\\jre\\bin; C:\\Program Files\\java\\jdk1.8.0\\bin ', ' homedrive ': ' C: ', ' PATH ': ' C:\\Program Files\\java\\jdk1.8.0\\bin; C:\\Program Files\\java\\jdk1.8.0\\jre\\bin; C:\\programdata\\oracle\\java\\javapath; C:\\Program Files (x86) \\Intel\\iCLS client\\; C:\\Program Files\\intel\\icls Client\\; C:\\Windows\\System32; C:\\Windows; C:\\windows\\system32\\wbem; c:\\windows\\system32\\windowspowershell\\v1.0\\; C:\\Program Files (x86) \\Intel\\Intel (R) Management Engine components\\dal; C:\\Program Files\\intel\\intel (R) Management Engine components\\dal; C:\\Program Files (x86) \\Intel\\Intel (R) Management Engine ComponentS\\ipt; C:\\Program Files\\intel\\intel (R) Management Engine components\\ipt; C:\\Program Files (x86) \\NVIDIA Corporation\\physx\\common; C:\\Program Files (x86) \\Microsoft SQL server\\100\\tools\\binn\\; C:\\Program Files\\Microsoft SQL Server\\100\\tools\\binn\\; C:\\Program Files\\Microsoft SQL Server\\100\\dts\\binn\\; C:\\Windows\\System32; C:\\Windows; C:\\windows\\system32\\wbem; c:\\windows\\system32\\windowspowershell\\v1.0\\;D: \\mydownloads\\matlab\\r2016a\\runtime\\win64;d:\\ Mydownloads\\matlab\\r2016a\\bin;d:\\mydownloads\\matlab\\r2016a\\polyspace\\bin; C:\\Program Files\\Microsoft SQL Server\\130\\tools\\binn\\;D: \\Matlab install\\runtime\\win64;d:\\matlab install\\ Bin;d:\\matlab Install\\polyspace\\bin; C:\\Program Files\\mysql\\mysql Server 5.7\\bin; F:\\dsystem\\mysql-5.7.18-winx64\\bin;d:\\devlop\\mingw\\bin; C:\\users\\asus\\appdata\\local\\programs\\python\\python36;d:\\python3.5.2\\scripts\\;D: \\Python3.5.2\\;D: \ \ Anaconda3-4;d:\\anaconda3-4\\scripts;d:\\anaconda3-4\\library\\biN E:\\tools\\winnt; E:\\msdev98\\bin; E:\\tools; C:\\users\\asus\\appdata\\local\\programs\\python\\python35; C:\\Program Files\\java\\jdk1.7.0_17\\bin; C:\\Program Files\\java\\jdk1.7.0_17\\jre\\bin; C:\\Program Files\\java\\jdk1.8.0\\bin; E:\\python Practice \\python35 Learning \\venv\\Scripts ', ' psmodulepath ': ' C:\\Program Files\\windowspowershell\\modules; C:\\windows\\system32\\windowspowershell\\v1.0\\modules ', ' COMMONPROGRAMW6432 ': ' C:\\Program Files\\Common Files ', ' Processor_level ': ' 6 ', ' Public ': ' C:\\users\\public ', ' number_of_processors ': ' 4 ', ' virtual_env ': ' E:\\python called Lee range \ \ Python35 Ying ^ \\venv ', ' java_home ': ' C:\\Program files\\java\\jre7 ', ' userprofile ': ' C:\\users\\asus ', ' COMSPEC ': ' c:\\ Windows\\system32\\cmd.exe ', ' allusersprofile ': ' C:\\programdata ', ' APPDATA ': ' c:\\users\\asus\\appdata\\roaming ', ' windir ': ' C:\\Windows ', ' PROGRAMDATA ': ' C:\\programdata ', ' ProgramFiles ': ' C:\\Program Files ', ' Matlab_java ': ' c:\\ Program Files\\java\\jre7 ', ' userdomain_roamingprofile ': ' desktop-hu5cspt ', ' PROMPT ': ' (venv) $P $g ', ' processor_identifier ': ' Intel64 Family 6 Model Stepping 3, Genuineintel ', ' mw_mingw64_loc ': ' d:\\tdm- GCC-64 ', ' LIB ': ' E:\\microsoft Visual studio\\vc98\\mfc\\lib; E:\\microsoft Visual studio\\vc98\\lib ', ' COMPUTERNAME ': ' desktop-hu5cspt ', ' dxsdk_dir ': ' D:\\directx sdk\\include ', ' Pythonioencoding ': ' UTF-8 ', ' localappdata ': ' c:\\users\\asus\\appdata\\local ', ' USERNAME ': ' ASUS ', ' SYSTEMROOT ': ' \ C ' \ Windows ', ' TMP ': ' c:\\users\\asus\\appdata\\local\\temp ', ' userdomain ': ' desktop-hu5cspt ', ' INCLUDE ': ' e:\\ Microsoft Visual Studio\\vc98\\atl\\include; E:\\microsoft Visual Studio\\vc98\\mfc\\include; E:\\microsoft Visual studio\\vc98\\include ', ' TEMP ': ' c:\\users\\asus\\appdata\\local\\temp ', ' PROGRAMW6432 ': ' c:\\ Program Files ', ' processor_revision ': ' 4e03 ', ' fps_browser_app_profile_string ': ' Internet Explorer ', ' CLASSPATH ': ' \ C \program Files\\java\\jdk1.7.0_17\\lib; C:\\Program Files\\java\\jdk1.7.0_17\\lib\\dt.jar; C:\\Program Files\\java\\jdk1.7.0_17\\lib\\tools.jar; C:\\proGram files\\java\\jdk1.8.0\\lib; C:\\Program Files\\java\\jdk1.7.0_17\\lib\\dt.jar; C:\\Program Files\\java\\jdk1.7.0_17\\lib\\tools.jar ', ' fps_browser_user_profile_string ': ' Default ', ' HOMEPATH ': ' \ \users\\asus ', ' CommonProgramFiles (X86) ': ' C:\\Program Files (x86) \\Common files ', ' commonprogramfiles ': ' C:\\Program Files\\Common Files '})

Os.makedirs (R'E:\a\b\c\d')#recursive creation of multilevel catalogsOs.removedirs (R'E:\a\b\c\d')#from the back to determine whether the directory is empty, if it is empty deleteOs.mkdir (R'e:\a')#only one level directory can be created at a timeOs.rmdir (R'e:\a')#only one directory can be deleted at a time, if it is empty, do not deleteOs.remove (R'E:\CLion\CLion 2017.2.2\build.txt')#Deleting Files
 1  print  (Os.listdir (R ' E:\CLion\CLion 2017.2.2  " )) #   2  os.rename (r " e:\python Practice \fib.py   ", R"  e:\ Python practice \fibnan1.py   ") #   rename  3  print  (Os.stat (R '  " ) #   file or directory status information  

[' bin ', ' help ', ' jre64 ', ' lib ', ' license ', ' plugins ']
Os.stat_result (st_mode=16895, st_ino=18295873486193234, st_dev=2227732002, St_nlink=1, St_uid=0, St_gid=0, st_size= 4096, st_atime=1516964219, st_mtime=1516964219, st_ctime=1499412376)

1 os.system ('ifconfig')  # run shell command
1 Print(Os.path.abspath (__file__))#Absolute Path2 Print(Os.path.dirname ('E:\python Practice \python35 Learning \day5\os_test.py'))#the last one \ Previous3 Print(Os.path.basename ('E:\python Practice \python35 Learning \day5'))#the last one \ after4 Print(Os.path.split ('E:/python Practice/python35 Learning/day5/os_test.py'))#separating files from directories to form tuples5 Print(Os.path.exists ('E:/python Practice/python35 Learning/day5'))#determine if a file or directory exists6 Print(Os.path.isabs ('python Practice/python35 Learning/day5/os_test.py'))#determine if it is an absolute path7 Print(Os.path.isfile ('E:/python Practice/python35 Learning/day5/os_test.py'))#determine if it is a file8 Print(Os.path.isdir ('E:/python Practice/python35 Learning/day5/os_test.py'))#determine if it is a directory9 Print(Os.path.join (R'E:/python Practice/python35 Learning/day5/'R'Day5.txt'))#Path ConnectionTen Print(Os.path.getatime ('E:/python Practice/python35 Learning/day5/os_test.py'))#Last access time Access One Print(Os.path.getmtime ('E:/python Practice/python35 Learning/day5/os_test.py'))#last modified on modify

Python Modules (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.