regpath - pathlib和winreg
项目描述
依赖项
Python 3.4, 3.5
pathlib (Python 3.4的内置库)
安装
pip install regpath
示例
导入
>>> from regpath import RegistryPath
创建对象
>>> p = RegistryPath('HKCU')
访问PurePath兼容属性
>>> p
RegistryPath('HKCU')
>>> print(p)
HKCU
>>> p.drive, p.root, p.parts
('HKCU', '', ('HKCU',))
列出键
>>> list(p.iterdir())
[RegistryPath('HKCU/AppEvents'), RegistryPath('HKCU/AppXBackupContentType'), RegistryPath('HKCU/Console'),
RegistryPath('HKCU/Control Panel'), RegistryPath('HKCU/Environment'), RegistryPath('HKCU/EUDC'),
RegistryPath('HKCU/Keyboard Layout'), RegistryPath('HKCU/Network'), RegistryPath('HKCU/Printers'),
RegistryPath('HKCU/Software'), RegistryPath('HKCU/System'), RegistryPath('HKCU/Volatile Environment')]
连接路径
>>> p = p / 'Environment'
>>> p
RegistryPath('HKCU/Environment')
>>> print(p)
HKCU\Environment
>>> p.drive, p.root, p.parts
('HKCU', '\\', ('HKCU', 'Environment'))
列出值
>>> list(p) ['TEMP', 'TMP'] >>> p['Temp'] '%USERPROFILE%\\AppData\\Local\\Temp'
然后
>>> p = RegistryPath(r'HKCU\Software\{d017c5cb-d6a6-453e-b41a-f3dc270628c0}\subkey')
>>> p.exists()
False
>>> p.mkdir(parents=True)
>>> p.exists()
True
>>> list(p)
[]
>>> p[''] = 'This is unnamed value.'
>>> list(p)
['']
>>> p['']
'This is unnamed value.'
>>> p['number'] = 0x12345678
>>> p['number']
305419896
>>> list(p)
['', 'number']
>>> del p['number']
>>> list(p)
['']
>>> del p['']
>>> list(p)
[]
>>> p['msg'] = 'hello, world'
>>> p.parent.rmdir()
Traceback (most recent call last):
...
PermissionError: [WinError 5] Access is denied.
>>> p.parent.rmtree()
>>> p.parent.exists()
False
>>> p.exists()
False
>>> list(p)
Traceback (most recent call last):
...
OSError: [WinError 1018] Illegal operation attempted on a Registry key which has been marked for deletion.
项目详情
关闭
regpath-0.1.0.zip的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 393e245217087d2fd68b8185b1d79307efe9f00332fd68dd8ba1b66defd0281a |
|
| MD5 | d93664c5caec0e11f8ad3502248fe66e |
|
| BLAKE2b-256 | 8bb61038019f73806236e34c869bf3f0ad744a4774f3cd54e9a24031a017daa8 |