os sys 模块使用笔记
os类 进行操作系统控制
import os
print(os.name)
nt
print(os.environ)
print(os.environ['path'])
environ({'ALLUSERSPROFILE': 'C:\\ProgramData', 'APPCODE_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\appcode.vmoptions', 'APPDATA': 'C:\\Users\\JX1402006\\AppData\\Roaming', 'AUTINSTLOG': 'C:\\ProgramData\\Siemens\\Automation\\Logfiles\\Setup\\', 'CLION_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\clion.vmoptions', 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files', 'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common Files', 'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files', 'COMPUTERNAME': 'JX-140006-GCDQ', 'COMSPEC': 'C:\\Windows\\system32\\cmd.exe', 'DATAGRIP_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\datagrip.vmoptions', 'DATASPELL_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\dataspell.vmoptions', 'DRIVERDATA': 'C:\\Windows\\System32\\Drivers\\DriverData', 'FPS_BROWSER_APP_PROFILE_STRING': 'Internet Explorer', 'FPS_BROWSER_USER_PROFILE_STRING': 'Default', 'GATEWAY_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\gateway.vmoptions', 'GOLAND_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\goland.vmoptions', 'HOMEDRIVE': 'Z:', 'HOMEPATH': '\\', 'HOMESHARE': '\\\\172.17.200.11\\zjkeboda', 'IDEA_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\idea.vmoptions', 'JETBRAINSCLIENT_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\jetbrainsclient.vmoptions', 'JETBRAINS_CLIENT_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\jetbrains_client.vmoptions', 'LOCALAPPDATA': 'C:\\Users\\JX1402006\\AppData\\Local', 'LOGONSERVER': '\\\\JX-DC02', 'MOZ_PLUGIN_PATH': 'C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\plugins\\', 'MSMPI_BENCHMARKS': 'C:\\Program Files\\Microsoft MPI\\Benchmarks\\', 'MSMPI_BIN': 'C:\\Program Files\\Microsoft MPI\\Bin\\', 'NUMBER_OF_PROCESSORS': '12', 'ONEDRIVE': 'C:\\Users\\JX1402006\\OneDrive', 'OS': 'Windows_NT', 'PATH': 'D:\\anaconda3;D:\\anaconda3\\Library\\mingw-w64\\bin;D:\\anaconda3\\Library\\usr\\bin;D:\\anaconda3\\Library\\bin;D:\\anaconda3\\Scripts;D:\\python3.6\\Scripts\\;D:\\python3.6\\;C:\\Program Files (x86)\\VMware\\VMware Workstation\\bin\\;C:\\Python37\\Scripts\\;C:\\Python37\\;C:\\Program Files\\Python37\\Scripts\\;C:\\Program Files\\Python37\\;C:\\Program Files\\Microsoft MPI\\Bin\\;C:\\Program Files\\Common Files\\Siemens\\Automation\\Simatic OAM\\bin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Enterprise Vault\\EVClient\\x64\\;C:\\Program Files (x86)\\Microsoft SQL Server\\Client SDK\\ODBC\\110\\Tools\\Binn\\;C:\\Program Files (x86)\\Microsoft SQL Server\\120\\Tools\\Binn\\;C:\\Program Files (x86)\\Microsoft SQL Server\\120\\DTS\\Binn\\;C:\\Program Files (x86)\\Microsoft SQL Server\\150\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\150\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\150\\DTS\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files\\dotnet\\;C:\\Users\\JX1402006\\AppData\\Roaming\\Python\\Python37\\Scripts;D:\\Program Files\\PuTTY\\;C:\\Program Files\\Python37\\Scripts;C:\\Program Files\\Python37;C:\\Users\\JX1402006\\AppData\\Local\\Microsoft\\WindowsApps;c:\\program files\\esafenet\\cobra docguard client;D:\\Program Files\\JetBrains\\PyCharm Community Edition 2021.3.2\\bin;;C:\\Program Files\\Azure Data Studio\\bin;C:\\Users\\JX1402006\\AppData\\Roaming\\Python\\Python37\\Scripts;d:\\Program Files\\JetBrains\\PyCharm 2022.1\\bin;;C:\\Users\\JX1402006\\.dotnet\\tools', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW', 'PHPSTORM_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\phpstorm.vmoptions', 'PROCESSOR_ARCHITECTURE': 'AMD64', 'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 166 Stepping 0, GenuineIntel', 'PROCESSOR_LEVEL': '6', 'PROCESSOR_REVISION': 'a600', 'PROGRAMDATA': 'C:\\ProgramData', 'PROGRAMFILES': 'C:\\Program Files', 'PROGRAMFILES(X86)': 'C:\\Program Files (x86)', 'PROGRAMW6432': 'C:\\Program Files', 'PSMODULEPATH': 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules;C:\\Program Files (x86)\\Microsoft SQL Server\\120\\Tools\\PowerShell\\Modules\\;C:\\Program Files (x86)\\Microsoft SQL Server\\150\\Tools\\PowerShell\\Modules\\', 'PUBLIC': 'C:\\Users\\Public', 'PYCHARM': 'd:\\Program Files\\JetBrains\\PyCharm 2022.1\\bin;', 'PYCHARM COMMUNITY EDITION': 'D:\\Program Files\\JetBrains\\PyCharm Community Edition 2021.3.2\\bin;', 'PYCHARM_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\pycharm.vmoptions', 'RIDER_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\rider.vmoptions', 'RUBYMINE_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\rubymine.vmoptions', 'SESSIONNAME': 'Console', 'SIMATIC_OAM': 'C:\\Program Files\\Common Files\\Siemens\\Automation\\Simatic OAM', 'SIMATIC_OAM_DATA': 'C:\\ProgramData\\Siemens\\Automation\\Simatic OAM', 'SYSTEMDRIVE': 'C:', 'SYSTEMROOT': 'C:\\Windows', 'TEMP': 'C:\\Users\\JX1402~1\\AppData\\Local\\Temp', 'TMP': 'C:\\Users\\JX1402~1\\AppData\\Local\\Temp', 'UATDATA': 'C:\\Windows\\CCM\\UATData\\D9F8C395-CAB8-491d-B8AC-179A1FE1BE77', 'USERDNSDOMAIN': 'KEBODA.COM', 'USERDOMAIN': 'KEBODA', 'USERDOMAIN_ROAMINGPROFILE': 'KEBODA', 'USERNAME': 'jx1402006', 'USERPROFILE': 'C:\\Users\\JX1402006', 'WEBIDE_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\webide.vmoptions', 'WEBSTORM_VM_OPTIONS': 'D:\\JetBrains Active\\ja-netfilter-all\\vmoptions\\webstorm.vmoptions', 'WINDIR': 'C:\\Windows', 'ZES_ENABLE_SYSMAN': '1', 'CONDA_PREFIX': 'D:\\anaconda3', 'PYDEVD_USE_FRAME_EVAL': 'NO', 'JPY_INTERRUPT_EVENT': '3428', 'IPY_INTERRUPT_EVENT': '3428', 'JPY_PARENT_PID': '3432', 'TERM': 'xterm-color', 'CLICOLOR': '1', 'FORCE_COLOR': '1', 'CLICOLOR_FORCE': '1', 'PAGER': 'cat', 'GIT_PAGER': 'cat', 'MPLBACKEND': 'module://matplotlib_inline.backend_inline'})
D:\anaconda3;D:\anaconda3\Library\mingw-w64\bin;D:\anaconda3\Library\usr\bin;D:\anaconda3\Library\bin;D:\anaconda3\Scripts;D:\python3.6\Scripts\;D:\python3.6\;C:\Program Files (x86)\VMware\VMware Workstation\bin\;C:\Python37\Scripts\;C:\Python37\;C:\Program Files\Python37\Scripts\;C:\Program Files\Python37\;C:\Program Files\Microsoft MPI\Bin\;C:\Program Files\Common Files\Siemens\Automation\Simatic OAM\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Enterprise Vault\EVClient\x64\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\dotnet\;C:\Users\JX1402006\AppData\Roaming\Python\Python37\Scripts;D:\Program Files\PuTTY\;C:\Program Files\Python37\Scripts;C:\Program Files\Python37;C:\Users\JX1402006\AppData\Local\Microsoft\WindowsApps;c:\program files\esafenet\cobra docguard client;D:\Program Files\JetBrains\PyCharm Community Edition 2021.3.2\bin;;C:\Program Files\Azure Data Studio\bin;C:\Users\JX1402006\AppData\Roaming\Python\Python37\Scripts;d:\Program Files\JetBrains\PyCharm 2022.1\bin;;C:\Users\JX1402006\.dotnet\tools
r = r'C:\Users\JX1402006\Desktop\web'
for item in os.walk(r):
print(item)
('C:\\Users\\JX1402006\\Desktop\\web', ['pc'], ['01d012c856a112073bc1092b45a5fde5_512_511.jpg', '101.mp4', '101.png', '103.mp4', '103.png', '104.png', '105.mp4', '107.mp4', '1102.png', '1692947951113.jpg', '2d88d936-7bc4-11eb-94a5-000c2962ebed.jpg', '33.PNG', '43382dfdc97f4268ac8178feb519aed1.png', '44.json', '44.PNG', '55.json', '55.PNG', '66.PNG', '90620a537eb20e3a122f77b455843a3.jpg', '9a890ed18df8a12a42de36e7bc3bc5a.jpg', '9deacd4b3a57b3705d7fa92d9ad7aa4.png', 'a40610fcc35c7e5fb208b048a3625d1c.mp4', 'ability_ground.jpg', 'advantage.png', 'aging_auto1.png', 'aging_auto2.png', 'aging_car1.png', 'aging_car2.png', 'aging_line1.png', 'aging_line2.png', 'AI.png', 'AI_label.jpg', 'AI_var.jpg', 'Ak36.png', 'Ak51.png', 'back_bt.png', 'battery_effect1.png', 'battery_effect2.png', 'battery_img.png', 'battery_logo.png', 'beng.png', 'black8.png', 'blue1.png', 'cad.png', 'cec57fd4ba0651d7c27e6439462f0df.png', 'ding.gif', 'ding.mp4', 'ding1.gif', 'electronic.png', 'exp1.jpg', 'exp2.jpg', 'Flow_img.png', 'Flow_logo.png', 'guide.png', 'gule.png', 'gule_value.png', 'handbook.png', 'hongtu1.png', 'Image_20230831103819038.bmp', 'Image_20230831104148157.bmp', 'intelligent_en.png', 'intelligent_hard.png', 'intelligent_local.png', 'intelligent_opc.png', 'intelligent_pdps.png', 'intelligent_pro.png', 'intelligent_remote.png', 'intelligent_st.png', 'intelligent_test.png', 'line.png', 'line_exp.png', 'line_img.jpg', 'line_peculiarity.png', 'LOGO.png', 'LOGO1.ico', 'menu.png', 'message.png', 'Navy_blue.jpg', 'Oil.png', 'operate.png', 'other.png', 'pallet_car3.png', 'pallet_car4.png', 'pallet_magazine3.png', 'pallet_magazine4.png', 'pallet_pull3.png', 'pallet_pull4.png', 'pei_effect1.png', 'pei_effect2.png', 'pei_img.png', 'pei_logo.jpg', 'pei_logo.png', 'plate_img.png', 'plate_logo.png', 'power_img.png', 'power_logo.png', 'pro_aging.png', 'pro_feed.png', 'pro_pallet.png', 'pro_vision.png', 'quan.gif', 'quan.mp4', 'R-C.jpg', 'R-C.png', 'red4.png', 'robot.png', 'scara.png', 'seal.png', 'seqia3.png', 'sing.png', 'software.png', 'standard.png', 'standard_img.jpg', 'standard_list.png', 'standard_type.png', 'te.mp4', 'tia.png', 'tools.png', 't_car1.png', 't_food.png', 't_medicine.png', 'v2-b7bb519bbcdf53bddaad19fc7ff01f27_720w.jpg', 'v2-e03eaa97a401357c7cba796d016422f5_r.jpg', 'value.png', 'vi29_sm0308.png', 'vision.png', 'Vision_alg.png', 'Vision_map.png', '介绍提要.txt', '媒体1.mp4', '微信图片_20230105144802.png', '新建 Microsoft PowerPoint 演示文稿.pptx', '新视频.mp4'])
('C:\\Users\\JX1402006\\Desktop\\web\\pc', ['Config', 'Log', 'Model', 'TestData'], [])
('C:\\Users\\JX1402006\\Desktop\\web\\pc\\Config', [], [])
('C:\\Users\\JX1402006\\Desktop\\web\\pc\\Log', [], [])
('C:\\Users\\JX1402006\\Desktop\\web\\pc\\Model', [], [])
('C:\\Users\\JX1402006\\Desktop\\web\\pc\\TestData', [], [])
files_list = os.listdir(r)
files_list
['01d012c856a112073bc1092b45a5fde5_512_511.jpg',
'101.mp4',
'101.png',
'103.mp4',
'103.png',
'104.png',
'105.mp4',
'107.mp4',
'1102.png',
'1692947951113.jpg',
'2d88d936-7bc4-11eb-94a5-000c2962ebed.jpg',
'33.PNG',
'43382dfdc97f4268ac8178feb519aed1.png',
'44.json',
'44.PNG',
'55.json',
'55.PNG',
'66.PNG',
'90620a537eb20e3a122f77b455843a3.jpg',
'9a890ed18df8a12a42de36e7bc3bc5a.jpg',
'9deacd4b3a57b3705d7fa92d9ad7aa4.png',
'a40610fcc35c7e5fb208b048a3625d1c.mp4',
'ability_ground.jpg',
'advantage.png',
'aging_auto1.png',
'aging_auto2.png',
'aging_car1.png',
'aging_car2.png',
'aging_line1.png',
'aging_line2.png',
'AI.png',
'AI_label.jpg',
'AI_var.jpg',
'Ak36.png',
'Ak51.png',
'back_bt.png',
'battery_effect1.png',
'battery_effect2.png',
'battery_img.png',
'battery_logo.png',
'beng.png',
'black8.png',
'blue1.png',
'cad.png',
'cec57fd4ba0651d7c27e6439462f0df.png',
'ding.gif',
'ding.mp4',
'ding1.gif',
'electronic.png',
'exp1.jpg',
'exp2.jpg',
'Flow_img.png',
'Flow_logo.png',
'guide.png',
'gule.png',
'gule_value.png',
'handbook.png',
'hongtu1.png',
'Image_20230831103819038.bmp',
'Image_20230831104148157.bmp',
'intelligent_en.png',
'intelligent_hard.png',
'intelligent_local.png',
'intelligent_opc.png',
'intelligent_pdps.png',
'intelligent_pro.png',
'intelligent_remote.png',
'intelligent_st.png',
'intelligent_test.png',
'line.png',
'line_exp.png',
'line_img.jpg',
'line_peculiarity.png',
'LOGO.png',
'LOGO1.ico',
'menu.png',
'message.png',
'Navy_blue.jpg',
'Oil.png',
'operate.png',
'other.png',
'pallet_car3.png',
'pallet_car4.png',
'pallet_magazine3.png',
'pallet_magazine4.png',
'pallet_pull3.png',
'pallet_pull4.png',
'pc',
'pei_effect1.png',
'pei_effect2.png',
'pei_img.png',
'pei_logo.jpg',
'pei_logo.png',
'plate_img.png',
'plate_logo.png',
'power_img.png',
'power_logo.png',
'pro_aging.png',
'pro_feed.png',
'pro_pallet.png',
'pro_vision.png',
'quan.gif',
'quan.mp4',
'R-C.jpg',
'R-C.png',
'red4.png',
'robot.png',
'scara.png',
'seal.png',
'seqia3.png',
'sing.png',
'software.png',
'standard.png',
'standard_img.jpg',
'standard_list.png',
'standard_type.png',
'te.mp4',
'tia.png',
'tools.png',
't_car1.png',
't_food.png',
't_medicine.png',
'v2-b7bb519bbcdf53bddaad19fc7ff01f27_720w.jpg',
'v2-e03eaa97a401357c7cba796d016422f5_r.jpg',
'value.png',
'vi29_sm0308.png',
'vision.png',
'Vision_alg.png',
'Vision_map.png',
'介绍提要.txt',
'媒体1.mp4',
'微信图片_20230105144802.png',
'新建 Microsoft PowerPoint 演示文稿.pptx',
'新视频.mp4']
os.mkdir()
os.makedirs()
os.remove()
os.rename()
print(os.getcwd())
D:\Data\Python\edu
os.chdir()
os.path.join(src, add)
os.path.abspath()
os.path.basename(os.getcwd())
os.path.dirname(os.getcwd())
os.path.split(os.getcwd())
os.path.exists()
os.path.isabs()
os.path.isfile()
os.path.isdir()
('D:\\Data\\Python', 'edu')
sys类 系统类
import sys
sys.argv
['D:\\anaconda3\\Lib\\site-packages\\ipykernel_launcher.py',
'-f',
'C:\\Users\\JX1402006\\AppData\\Roaming\\jupyter\\runtime\\kernel-a11f658e-1bb3-4367-93f2-cb094f811b66.json']
sys.platform
'win32'
sys.byteorder
'little'
sys.executable
'D:\\anaconda3\\python.exe'
sys.builtin_module_names
('_abc',
'_ast',
'_bisect',
'_blake2',
'_codecs',
'_codecs_cn',
'_codecs_hk',
'_codecs_iso2022',
'_codecs_jp',
'_codecs_kr',
'_codecs_tw',
'_collections',
'_contextvars',
'_csv',
'_datetime',
'_functools',
'_heapq',
'_imp',
'_io',
'_json',
'_locale',
'_lsprof',
'_md5',
'_multibytecodec',
'_opcode',
'_operator',
'_pickle',
'_random',
'_sha1',
'_sha256',
'_sha3',
'_sha512',
'_signal',
'_sre',
'_stat',
'_statistics',
'_string',
'_struct',
'_symtable',
'_thread',
'_tokenize',
'_tracemalloc',
'_typing',
'_warnings',
'_weakref',
'_winapi',
'_xxsubinterpreters',
'array',
'atexit',
'audioop',
'binascii',
'builtins',
'cmath',
'errno',
'faulthandler',
'gc',
'itertools',
'marshal',
'math',
'mmap',
'msvcrt',
'nt',
'sys',
'time',
'winreg',
'xxsubtype',
'zlib')
sys.path
['D:\\Data\\Python\\edu',
'D:\\anaconda3\\python311.zip',
'D:\\anaconda3\\DLLs',
'D:\\anaconda3\\Lib',
'D:\\anaconda3',
'',
'D:\\anaconda3\\Lib\\site-packages',
'D:\\anaconda3\\Lib\\site-packages\\win32',
'D:\\anaconda3\\Lib\\site-packages\\win32\\lib',
'D:\\anaconda3\\Lib\\site-packages\\Pythonwin']
sys.stdin
sys.stdout
sys.err
sys.getrefcount()
sys.getrecursionlimit()
sys.setrecursionlimit()
sys.getsizeof()
sys.int_info
sys.float_info