更快的操作系統是Python標準“ OS”模塊的置換式替換。更快的操作系統提供32個完全劃化的,優化和加速功能的功能,這些功能取代了os.path模塊中的功能。
多虧了更快的操作系統,您可以在一分鐘內處理1,400,000條路徑,而使用操作系統則需要一個多小時。
# Use Faster OS to save hours of processing time!
# The only thing you need to do is write...
import faster_os as os 快速地。最佳化.具有0個依賴關係。光。
使用更快的操作系統在:
Myquickmac Neo- Mac的AI驅動護理的革命性計劃-www.ambeteco.com/myquickmac-neo
Myquickmac Lite- AI文件管理的創新計劃-www.ambeteco.com/myquickmac-lite
4-Organizer Ultra-一個強大的程序,可以自動解開Windows PC,由AI-www.ambeteco.com/4-organizer-ultra提供支持
4-Organizer Nano-自動整理PC,並結束文件的無限混亂-www.ambeteco.com/4-organizer-nano
雨刮器AI-正在開發,即將提供
更快的操作系統是一種穩定的,可以生產的工具。
平均而言,更快的OS函數比OS模塊的原始功能快1504% 。
最常用的功能( split , join , splitext )平均更快1215% :
| 姓名 | 時間更快 | 更快的操作系統:過程1,000,000路徑 | 操作系統:過程1,000,000路徑 |
|---|---|---|---|
join | 1530% | 14秒 | 3分20秒 |
splitext | 1059% | 8秒 | 1分33秒 |
split | 1190% | 18秒 | 4分43秒 |
完整的基準結果:
| 功能 | 路徑量 | 時間更快 | 操作系統時間 | 更快的操作系統時間 |
|---|---|---|---|---|
| 分裂 | 5500 | 1105% | 0.8109 | 0.0733 |
| 拆分驅動器 | 5500 | 445% | 0.3849 | 0.0864 |
| 規範 | 5500 | 313% | 0.1608 | 0.0513 |
| Splitext | 5500 | 938% | 0.5017 | 0.0535 |
| 加入 | 5000 | 1442% | 1.4388 | 0.0997 |
| relath | 5500 | 3653% | 12.1418 | 0.3323 |
| Ismount | 5500 | 3620% | 71.5931 | 1.9776 |
| NORMPATH | 6500 | 326% | 1.9621 | 0.6026 |
| 擴展使用程序 | 5500 | 493% | 0.1539 | 0.0312 |
| 斜肌 | 5500 | 180% | 3.5075 | 1.9471 |
| iSabs | 5500 | 760% | 0.6911 | 0.0909 |
| Basename | 5500 | 1217% | 0.8403 | 0.0690 |
| dirname | 5500 | 1236% | 0.8473 | 0.0685 |
| CommonPath | 5000 | 738% | 4.4296 | 0.5998 |
| 普通冠軍 | 5000 | 356% | 0.9480 | 0.2661 |
多功能基準結果:
| 功能 | 塊數量(每50-100條路徑) | 時間更快 | 更快的操作系統時間 | 操作系統時間 |
|---|---|---|---|---|
| MULTI_COMMONPATH | 1000 | 761% | 0.1167 | 0.8886 |
| MULTI_COMMONPREFIX | 1000 | 435% | 0.0491 | 0.2137 |
| MULTI_ABSPATH | 4500 | 195% | 1.3105 | 2.5564 |
| Multi_ismount | 4500 | 6853% | 1.2878 | 88.2588 |
| Multi_expanduser | 4500 | 448% | 0.0680 | 0.3050 |
| MULTI_RELPATH | 1100 | 3772% | 0.0646 | 2.4374 |
| multi_split | 4500 | 1475% | 0.0442 | 0.6528 |
| Multi_splitdrive | 4500 | 628% | 0.0476 | 0.2989 |
| Multi_normcase | 4500 | 451% | 0.0298 | 0.1348 |
| MULTI_NOMPATH | 1300 | 362% | 0.1194 | 0.4324 |
| MULTI_BASENAME | 4500 | 1599% | 0.0423 | 0.6770 |
| multi_dirname | 4500 | 1644% | 0.0418 | 0.6888 |
| multi_isabs | 4500 | 1023% | 0.0539 | 0.5514 |
| Multi_splitext | 4500 | 1282% | 0.0318 | 0.4077 |
| MULTI_JOIN | 1000 | 1418% | 0.0204 | 0.2902 |
我們建議使用multi-functions時使用多功能,其中有250多個元素。對於較小的列表,使用multi-functions是無效的。
# Faster OS - a drop-in replacement for the 'OS' module
# Up to 6800% faster!
import faster_os
# All 'OS' functions you need, and even more!
# 32 rewritten functions, optimized for speed and performance.
faster_os . path . join ( '/' , 'some' , 'path' )
> >> '/some/path'
faster_os . path . split ( '/some/test/path' )
> >> ( '/some/test' , 'path' )
faster_os . path . join ( 'C: \ ' , 'Windows \ System32' , 'LogFiles' )
> >> 'C: \ Windows \ System32 \ LogFiles'
faster_os . path . split ( 'C: \ Users \ User \ Desktop' )
> >> ( 'C: \ Users \ User' , 'Desktop' )
# Works both for UNIX and for Windows!
# Everything works exactly the same as in 'OS':
# -- splitext --
faster_os . path . splitext ( 'hello world \ 123.ext' )
> >> ( 'hello world \ 123' , '.ext' )
faster_os . path . splitext ( 'C: \ sample_photo.jpg' )
> >> ( 'C: \ sample_photo' , '.jpg' )
# -- splitdrive --
faster_os . path . splitdrive ( 'C: \ HELLO WORLD \ SOME PATH' )
> >> ( 'C:' , ' \ HELLO WORLD \ SOME PATH' )
faster_os . path . splitdrive ( ' \ \ machine \ mountpoint \ directory \ etc \ ' )
> >> ( ' \ \ machine \ mountpoint' , ' \ directory \ etc \ ' )
# -- normpath --
faster_os . path . normpath ( 'C: \ \ hello \ \ \ world \ \ \ ' )
> >> 'C: \ hello \ world'
faster_os . path . normpath ( 'An invalid \ \ \ path \ \ with many slashes \ \ \ \ \ \ ' )
> >> 'An invalid \ path \ with many slashes'
# -- abspath --
faster_os . path . abspath ( 'Desktop' )
> >> 'D: \ Libraries \ Desktop \ Pys \ Big \ FasterOS \ Desktop'
faster_os . path . abspath ( 'Appdata \ Local' )
> >> 'D: \ Libraries \ Desktop \ Pys \ Big \ FasterOS \ Appdata \ Local'
# -- expanduser --
faster_os . path . expanduser ( '~ \ Downloads \ file.exe' )
> >> 'C: \ Users \ Dsibe \ Downloads \ file.exe'
faster_os . path . expanduser ( '~ \ Appdata' )
> >> 'C: \ Users \ Dsibe \ Appdata'
# -- normcase --
faster_os . path . normcase ( 'C:/HELLO WORLD/SOME/PATH/' )
> >> 'c: \ hello world \ some \ path \ '
faster_os . path . normcase ( 'C:/faster-os/a-unix-path/to-windows/path' )
> >> 'c: \ faster-os \ a-unix-path \ to-windows \ path'
# -- isabs --
faster_os . path . isabs ( 'C: \ Users \ User' )
> >> True
faster_os . path . isabs ( '~ \ user' )
> >> False
faster_os . path . isabs ( '%USERPROFILE% \ hi' )
> >> False
# -- basename --
faster_os . path . basename ( 'C: \ HELLO WORLD \ SOME PATH' )
> >> 'SOME PATH'
faster_os . path . basename ( 'C: \ faster-os' )
> >> 'faster-os'
# -- dirname --
faster_os . path . dirname ( 'C: \ HELLO WORLD \ SOME PATH' )
> >> 'C: \ HELLO WORLD'
faster_os . path . dirname ( 'C: \ faster-os' )
> >> 'C: \ '
# -- commonpath --
faster_os . path . commonpath ([
'C: \ \ Common' , 'C: \ \ Common \ \ ' , 'C: \ \ Common \ \ 123' , 'C: \ \ Common \ \ Common' ,
'C: \ \ Common \ \ abtco \ \ faster_os'
])
> >> 'C: \ Common'
# -- commonprefix--
faster_os . path . commonprefix ([
'C: \ \ ' , 'C: \ \ 1 \ \ 123/123/123 \ \ 123' , 'C: \ \ hello world \ \ some path' ,
'C: \ \ hello world \ \ some path \ \ '
])
> >> 'C: \ '
# And 21 more functions...
# Also, Faster OS also offers special 'multi-functions'.
# Use them to process extra large lists, containing hundreds of thousands of elements!
multi_abspath , multi_basename , multi_commonpath , multi_commonprefix , multi_dirname , multi_expanduser , multi_isabs , multi_ismount , multi_join , multi_normcase , multi_normpath , multi_relpath , multi_split , multi_splitdrive , multi_splitext
# For example:
faster_os . multi_join ([
( 'path/to/join' , 'some path' ),
( 'path/to/join' , 'other path' ),
( 'path/to/join' , 'other path 2' ),
( 'path/to/join' , 'other path 3' ),
...
])
# We recommend using multi-functions over lists with more than 250 elements.
# Even further, Faster OS re-implements removedirs and adds remove_multiple_dirs
faster_os . removedirs ( 'C: \ This \ Path \ Will \ Be \ Deleted' ) pip install faster_os --upgrade
克隆存儲庫: git clone https://github.com/American-Best-Technologies-Company/faster-os.git
運行python3 setup.py build_ext
完畢!驗證安裝: import faster_os
如果給定的參數有效,則更快的OS與OS模塊完全相同。這意味著,如果您在任何有效的路徑上使用更快的操作系統,則它將與OS模塊完全一樣。
如果您將一些無效的路徑作為參數以更快的操作函數,那麼它提出的大多數異常將與OS模塊提出的函數匹配。
例如,在這種情況下,OS和更快的OS提出的例外是相同的:
import os
os . path . join ( 'some path' , None )
> >> TypeError : join () argument must be str , bytes , or os . PathLike object , not 'NoneType'
import faster_os
faster_os . path . join ( 'some path' , None )
> >> TypeError : sequence item 0 : expected str instance , NoneType found但是有時候,提出的例外可能會有所不同:
import os
os . path . normcase ( None )
> >> TypeError : expected str , bytes or os . PathLike object , not NoneType
import faster_os
faster_os . path . normcase ( None )
> >> AttributeError : 'NoneType' object has no attribute 'replace'這樣做的主要原因是更快的OS:速度的主要目標。
添加類型和路徑有效性檢查將顯著減慢更快的OS。目前,我們不打算在更快的OS功能中添加任何類型檢查或某些驗證。因此,例外可能不是那麼可讀或易於理解。
目前,更快的操作系統僅支持str 。 bytes支持將在下一個更新中添加。也許,即使是os.PathLike對像也會在下一個版本中得到支持。
Python 3
C構建工具:
對於Windows:安裝了Visual Studio
對於UNIX:GCC(可能已經安裝了)
對於MacOS:安裝了Xcode CMD工具(在終端中輸入gcc以檢查是否已安裝)
更快的OS已根據Mozilla公共許可證2.0獲得許可。這意味著您可以在封閉的源代碼中將其用於商業/專有項目。您無需披露源代碼。
我們建議閱讀官方的OS模塊文檔,因為所有更快的OS函數都會從OS功能中“鏡像”。在下面,您可以在所有更快的操作系統功能上找到簡短的文檔。
faster_os.path.normpath(path: str) -> str
將路徑歸一化:在Windows上(或UNIX上的相反)替換'/'to',並進行與''相關的其他更改。和 '..'。
faster_os.path.normcase(path: str) -> str
降低路徑( str.lower ),然後在Windows上(或Unix上的相反)替換為'/''。
faster_os.path.split(path: str) -> tuple
將元組返回,該路徑分裂為目錄名稱和基本名稱:
示例:'一些/示例/路徑' - >('一些/示例','path')
faster_os.path.splitdrive(path: str) -> tuple
僅在Windows上有意義:將路徑分為驅動器和路徑。
示例: 'C:\Windows' -> ('C:', '\Windows')
faster_os.path.isabs(path: str) -> cython.bint
檢查路徑是否絕對。
例子:
'C:\some absolute\path' -> True
'some\relative\path\' -> False
faster_os.path.join(path: str, *paths) -> str
使用平台定界符('/'或'')加入所有給定路徑。
例子:
faster_os.path.('C:\', 'some', 'path') -> 'C:\some\path'
faster_os.path.splitext(path: str) -> tuple
將路徑分為路徑和延伸。
例子:
'a photo.jpg' -> ('a photo', '.jpg')
faster_os.path.basename(path: str) -> str
返迴路徑的基本名稱。
'C:\some absolute\path' -> 'path'
faster_os.path.dirname(path: str) -> str
返迴路徑的目錄名稱。
'C:\some absolute\path' -> 'C:\some absolute\'
faster_os.path.ismount(path: str) -> cython.bint
檢查路徑是否是安裝點。
faster_os.path.expanduser(path: str) -> str
將“〜”擴展到用戶配置文件或家庭路徑中。
例子:
'~Desktop' - > 'C: \ Users \ Desktop
'~ \ Desktop' - > 'C: \ Users \ User \ Desktop
^ ^ notice this slash faster_os.path.relpath(tail: str, root=None) -> str
根據root計算tail的相對路徑。
如果root沒有,則將其分配給當前的工作目錄os.getcwd() 。
faster_os.path.commonprefix(paths) -> str
找到給定路徑的常見前綴。
例子:
['faster_os/abc', 'faster_os/abcde', 'faster_os/abc123'] -> 'faster_os/abc'
faster_os.path.commonpath(paths) -> str
找到給定路徑的常見路徑。
與CommonPrefix相反,找到了完整的路徑。
例子:
['faster_os/abc', 'faster_os/abcde', 'faster_os/abc123'] -> 'faster_os'
faster_os.path.abspath(path: str) -> str
嘗試使用操作系統的API獲取絕對路徑,或者落後於使用CWD加入路徑。
faster_os.path.multi_split(paths) -> list
採用任何疑問(列表,元組等),並應用於每個元素。
返回列表。
faster_os.path.multi_normpath(paths) -> list
獲取任何可觀的(列表,元組等),並將標準路徑應用於每個元素。
返回列表。
faster_os.path.multi_normcase(paths) -> list
將任何可觀的(列表,元組等)應用於每個元素。
返回列表。
faster_os.path.multi_splitdrive(paths) -> list
將任何可觀的(列表,元組等)應用於每個元素。
返回列表。
faster_os.path.multi_isabs(paths) -> list
將任何可觀的(列表,元組等)獲取,並將ISAB應用於每個元素。
返回列表。
faster_os.path.multi_join(paths) -> list
獲取任何可觀的(列表,元組等),並適用於每個元素。
返回列表。
faster_os.path.multi_splitext(paths) -> list
將任何可觀的東西(列表,元組等)應用於每個元素。
返回列表。
faster_os.path.multi_basename(paths) -> list
獲取任何可觀的(列表,元組等),並將Basename應用於每個元素。
返回列表。
faster_os.path.multi_dirname(paths) -> list
獲取任何可觀的(列表,元組等),並將DirName應用於每個元素。
返回列表。
faster_os.path.multi_relpath(paths) -> list
獲取任何疑問(列表,元組等),並將relate應用於每個元素。
返回列表。
faster_os.path.multi_expanduser(paths) -> list
將任何可觀的(列表,元組等)應用於每個元素。
返回列表。
faster_os.path.multi_ismount(paths) -> list
獲取任何可觀的(列表,元組等),並將其應用於每個元素。
返回列表。
faster_os.path.multi_abspath(paths) -> list
拿任何可覺得的(列表,元組等),並在每個元素上應用ABSPATH。
返回列表。
faster_os.path.multi_commonprefix(paths) -> list
獲取任何可觀的(列表,元組等),並在每個元素上應用共同點。
返回列表。
faster_os.path.multi_commonpath(paths) -> list
將任何可觀的(列表,元組等)用於每個元素。
返回列表。
faster_os.removedirs(path) -> None
刪除所有路徑組件,直到增加例外。
removedirs將嘗試刪除每個目錄,直到引起錯誤為止,例如,目錄不是空的或有權限錯誤:例如::
Given path "C:UsersUserDesktopmany f oldershere"
Delete "C:UsersUserDesktopmany f oldershere"
Delete "C:UsersUserDesktopmany f olders"
Delete "C:UsersUserDesktopmany"
Delete "C:UsersUserDesktop " -> ERROR - return faster_os.remove_multiple_dirs(paths) -> None
將任何可觀的(列表,元組等) removedirs每個元素。