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第三方库


热门话题
java问题,包括来自非索引存储库的依赖关系   java lombok项目是否支持openjdk 11?   使用自定义摄像头的java在不同的安卓设备上会遇到很多问题   java如何在我的所有集成测试文件上执行beforeach   EclipseJava。lang.NoClassDefFoundError:org/java/plugin/ExtensionPoint   java Android陷入了从SQLite获取本周数据的困境   ClientResponseFilter中的java注入EJB   java读取Elasticsearch,Spark获取精确字段   java如何检查一个列表是否具有与另一个列表相同的元素,并且能够有重复的元素   java印地语文本验证按钮+selenium中的哪个   http如何使用Java发出多部分/formdata POST请求?   java在imageview上启动活动单击自定义阵列适配器   java如何根据表的第二列中的值设置第一列中的复选框?   javamysql与JDBC的连接