Regpath-Pathlib and Winreg

regpath的Python项目详细描述


依赖关系

  • Python3.4,3.5
  • pathlib(python 3.4中的标准库)

安装

pip install regpath

示例

导入:

>>> from regpath import RegistryPath

创建对象:

>>> p = RegistryPath('HKCU')

访问purepath Compatible属性是:

>>> 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.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaEclipseMars没有保存首选项   java梯度同步失败:原因:启动失败:   java如何从嵌套的JSON获取数据?   java如何判断可观察对象中的任何对象满足一个条件?   java将字符串转换为保持相同值的byte[]数组   java有没有办法绕过AuditingEntityListener为测试设置数据?   从/usr/share/java中解析linux JAR依赖关系   安卓 My java函数抛出nullpointerexception?   java Gradle使用正确版本的依赖项   JBoss和Java6中带注释的WebService中的web服务ClassCastException   java如何修复codename one中的简单逻辑错误?   java如何迭代矩阵的索引?   java如何在JPanel不可见时将其保存为图像?   java HashMap如何在Kotlin中实现MutableMap接口?   javascript如何在单击后加载特定片段?   EclipseJava为纳什均衡获取所有玩家/策略组合   JavaSpring:Web服务REST在JSON上产生双反斜杠   java为什么ServletContext#getRealPath(“/”)返回相对路径?   java当我的游戏应该重新启动时,我应该如何处理重置SurfaceView和线程?