Microsoft Windows [版本 10.0.19041.208](c)2020 Microsoft Corporation. 保留所有权利。
C:\Users\徐达>control
C:\Users\徐达>python
Python 3.8.2(tags/v3.8.2:7b3ab59, Feb 252020,23:03:10)[MSC v.191664 bit (AMD64)] on win32
Type "help","copyright","credits"or"license"for more information.>>>import os
>>>dir(os)['DirEntry','F_OK','MutableMapping','O_APPEND','O_BINARY','O_CREAT','O_EXCL','O_NOINHERIT','O_RANDOM','O_RDONLY','O_RDWR','O_SEQUENTIAL','O_SHORT_LIVED','O_TEMPORARY','O_TEXT','O_TRUNC','O_WRONLY','P_DETACH','P_NOWAIT','P_NOWAITO','P_OVERLAY','P_WAIT','PathLike','R_OK','SEEK_CUR','SEEK_END','SEEK_SET','TMP_MAX','W_OK','X_OK','_AddedDllDirectory','_Environ','__all__','__builtins__','__cached__','__doc__','__file__','__loader__','__name__','__package__','__spec__','_check_methods','_execvpe','_exists','_exit','_fspath','_get_exports_list','_putenv','_unsetenv','_wrap_close','abc','abort','access','add_dll_directory','altsep','chdir','chmod','close','closerange','cpu_count','curdir','defpath','device_encoding','devnull','dup','dup2','environ','error','execl','execle','execlp','execlpe','execv','execve','execvp','execvpe','extsep','fdopen','fsdecode','fsencode','fspath','fstat','fsync','ftruncate','get_exec_path','get_handle_inheritable','get_inheritable','get_terminal_size','getcwd','getcwdb','getenv','getlogin','getpid','getppid','isatty','kill','linesep','link','listdir','lseek','lstat','makedirs','mkdir','name','open','pardir','path','pathsep','pipe','popen','putenv','read','readlink','remove','removedirs','rename','renames','replace','rmdir','scandir','sep','set_handle_inheritable','set_inheritable','spawnl','spawnle','spawnv','spawnve','st','startfile','stat','stat_result','statvfs_result','strerror','supports_bytes_environ','supports_dir_fd','supports_effective_ids','supports_fd','supports_follow_symlinks','symlink','sys','system','terminal_size','times','times_result','truncate','umask','uname_result','unlink','urandom','utime','waitpid','walk','write']>>> os.environ
environ({'ALLUSERSPROFILE':'C:\\ProgramData','APPDATA':'C:\\Users\\徐达\\AppData\\Roaming','CLASSPATH':'.;C:\\Program Files\\Java\\jdk1.8.0_221\\lib\\dt.jar;C:\\Program Files\\Java\\jdk1.8.0_221\\lib\\tools.jar','COMMONPROGRAMFILES':'C:\\Program Files\\Common Files','COMMONPROGRAMFILES(X86)':'C:\\Program Files (x86)\\Common Files','COMMONPROGRAMW6432':'C:\\Program Files\\Common Files','COMPUTERNAME':'LAPTOP-QI10CO2B','COMSPEC':'C:\\Windows\\system32\\cmd.exe','DRIVERDATA':'C:\\Windows\\System32\\Drivers\\DriverData','FPS_BROWSER_APP_PROFILE_STRING':'Internet Explorer','FPS_BROWSER_USER_PROFILE_STRING':'Default','HOMEDRIVE':'C:','HOMEPATH':'\\Users\\徐达','JAVA_HOME':'C:\\Program Files\\Java\\jdk1.8.0_221','LOCALAPPDATA':'C:\\Users\\徐达\\AppData\\Local','LOGONSERVER':'\\\\LAPTOP-QI10CO2B','NUMBER_OF_PROCESSORS':'8','ONEDRIVE':'C:\\Users\\徐达\\OneDrive','OS':'Windows_NT','PATH':'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)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Program Files\\Java\\jdk1.8.0_221\\bin;D:\\Python38\\Scripts\\;D:\\Python38\\;C:\\Users\\徐达\\AppData\\Local\\Microsoft\\WindowsApps;;D:\\PyCharm Community Edition 2020.2.2\\bin;','PATHEXT':'.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC','PROCESSOR_ARCHITECTURE':'AMD64','PROCESSOR_IDENTIFIER':'Intel64 Family 6 Model 165 Stepping 2, GenuineIntel','PROCESSOR_LEVEL':'6','PROCESSOR_REVISION':'a502','PROGRAMDATA':'C:\\ProgramData','PROGRAMFILES':'C:\\Program Files','PROGRAMFILES(X86)':'C:\\Program Files (x86)','PROGRAMW6432':'C:\\Program Files','PROMPT':'$P$G','PSMODULEPATH':'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules','PUBLIC':'C:\\Users\\Public','PYCHARM COMMUNITY EDITION':'D:\\PyCharm Community Edition 2020.2.2\\bin;','SESSIONNAME':'Console','SYSTEMDRIVE':'C:','SYSTEMROOT':'C:\\Windows','TEMP':'C:\\Users\\徐达\\AppData\\Local\\Temp','TMP':'C:\\Users\\徐达\\AppData\\Local\\Temp','USERDOMAIN':'LAPTOP-QI10CO2B','USERDOMAIN_ROAMINGPROFILE':'LAPTOP-QI10CO2B','USERNAME':'徐达','USERPROFILE':'C:\\Users\\徐达','WINDIR':'C:\\Windows'})>>>
>>> exit()
C:\Users\徐达>cls
C:\Users\徐达>calc
C:\Users\徐达>python
Python 3.8.2(tags/v3.8.2:7b3ab59, Feb 252020,23:03:10)[MSC v.191664 bit (AMD64)] on win32
Type "help","copyright","credits"or"license"for more information.>>>import os
>>> os.system('calc')0>>> os.system('C:\Users\徐达\Documents\liuyuboMLppt)
File "<stdin>", line 1
os.system('C:\Users\徐达\Documents\liuyuboMLppt)^
SyntaxError: EOL while scanning string literal
>>> os.system('C:\Users\徐达\Documents\liuyuboMLppt')
File "<stdin>", line 1
SyntaxError:(unicode error)'unicodeescape' codec can't decode bytesin position 2-3: truncated \UXXXXXXXX escape
>>> os.system('C:\Users\徐达\Documents\liuyuboMLppt')
File "<stdin>", line 1
SyntaxError:(unicode error)'unicodeescape' codec can't decode bytesin position 2-3: truncated \UXXXXXXXX escape
>>> os.system('C://Users//徐达//Document//liuyuboMLppt')
系统找不到指定的路径。
1>>> os.sep
'\\'>>> os.system('C:\\Users\\徐达\\Docunment\\liuyuboMLppt')
系统找不到指定的路径。
1>>> os.system('C:\\Users\\徐达\\Docunments\\liuyuboMLppt')
File "<stdin>", line 1
os.system('C:\\Users\\徐达\\Docunments\\liuyuboMLppt')^
IndentationError: unexpected indent
>>> os.system('C:\\Users\\徐达\\Documents\\liuyuboMLppt')
File "<stdin>", line 1
os.system('C:\\Users\\徐达\\Documents\\liuyuboMLppt')^
IndentationError: unexpected indent
>>> os.system('C:\\Users\\徐达\\Documents\\liuyuboMLppt')'C:\Users\徐达\Documents\liuyuboMLppt' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
1>>> os.system('liuyuboMLppt')'liuyuboMLppt' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
1>>> os.getcwd()'C:\\Users\\徐达'>>> os.chdir('desktop')>>> os.getcwd()'C:\\Users\\徐达\\desktop'>>> os.listdir()['2020Python就业班 - 快捷方式.lnk','desktop.ini','eclipse - 快捷方式.lnk','Microsoft Edge.lnk','WPS Office.lnk','大黄蜂云课堂播放器.lnk','此电脑 -.lnk','百度网盘.lnk']>>> os.mkdir('hello')>>> os.mkdir('hello')
Traceback (most recent call last):
File "<stdin>", line 1,in<module>
FileExistsError:[WinError 183] 当文件已存在时,无法创建该文件。:'hello'>>> os.rename('hello','world')>>> os.remdir('world')
Traceback (most recent call last):
File "<stdin>", line 1,in<module>
AttributeError: module 'os' has no attribute 'remdir'>>> os.rmdir('world')>>> os.path
<module 'ntpath'from'D:\\Python38\\lib\\ntpath.py'>>>>
``>>>dir(os.path)['__all__','__builtins__','__cached__','__doc__','__file__','__loader__','__name__','__package__','__spec__','_abspath_fallback','_get_bothseps','_getfinalpathname','_getfinalpathname_nonstrict','_getfullpathname','_getvolumepathname','_nt_readlink','_readlink_deep','abspath','altsep','basename','commonpath','commonprefix','curdir','defpath','devnull','dirname','exists','expanduser','expandvars','extsep','genericpath','getatime','getctime','getmtime','getsize','isabs','isdir','isfile','islink','ismount','join','lexists','normcase','normpath','os','pardir','pathsep','realpath','relpath','samefile','sameopenfile','samestat','sep','split','splitdrive','splitext','stat','supports_unicode_filenames','sys']>>> os.getcwd()'C:\\Users\\徐达\\desktop'>>> os.listdir()['2020Python就业班 - 快捷方式.lnk','desktop.ini','eclipse - 快捷方式.lnk','Microsoft Edge.lnk','WPS Office.lnk','大黄蜂云课堂播放器.lnk','此电脑 -.lnk','百度网盘.lnk']>>> os.path.isdir('大黄蜂云课堂播放器.lnk')False>>> os.path.isdir('2020Python就业班 - 快捷方式.lnk')
File "<stdin>", line 1
os.path.isdir('2020Python就业班 - 快捷方式.lnk')^
IndentationError: unexpected indent
>>> os.path.isdir('2020Python就业班 - 快捷方式.lnk')False>>> os.listdir()['2020Python就业班 - 快捷方式.lnk','desktop.ini','eclipse - 快捷方式.lnk','Microsoft Edge.lnk','WPS Office.lnk','大黄蜂云课堂播放器.lnk','新建文件夹','此电脑 -.lnk','百度网盘.lnk']>>> os.path.isdir('新建文件夹')True>>> os.path.isfile('新建文件夹')False>>> os.path.exists('you')False>>> os.path.exists('新建文件夹')True>>> f="C:\\Users\\徐达\\desktop\\desktop.ini">>> os.path.exist(f)
Traceback (most recent call last):
File "<stdin>", line 1,in<module>
AttributeError: module 'ntpath' has no attribute 'exist'>>> os.path.exists(f)
File "<stdin>", line 1
os.path.exists(f)^
IndentationError: unexpected indent
>>> os.path.exists(f)True>>> os.path.iffile(f)
Traceback (most recent call last):
File "<stdin>", line 1,in<module>
AttributeError: module 'ntpath' has no attribute 'iffile'>>> os.path.isfile(f)
File "<stdin>", line 1
os.path.isfile(f)
^
SyntaxError: invalid character in identifier
>>> os.path.isfile(f)True>>> os.path.dirname(f)'C:\\Users\\徐达\\desktop'>>> os.path.split(f)('C:\\Users\\徐达\\desktop','desktop.ini')>>> os.path.basename(f)'desktop.ini'>>> name ="desktop.xxx.ini">>> name.split('.')['desktop','xxx','ini']>>> os.path.splitext(f)('C:\\Users\\徐达\\desktop\\desktop','.ini')>>> os.path.join('c:\\desktop','a','b','c')'c:\\desktop\\a\\b\\c'>>> f2 = os.path.join('c:\\desktop','a','b','c')>>> os.makedirs(f2)
```python
在这里插入代码片