读写.netrc文件。
tinynetrc的Python项目详细描述
在python中读写.netrc文件。
tinynetrc使用netrc 来自标准库的模块并添加了一些 改进:
- 添加写入功能。
- 使用修复std库bug 格式化.netrc文件。*
- 将.netrc解析为字典值,而不是元组。
*此错误在较新版本的python中已修复。
立即获取
pip install tinynetrc
tinynetrc支持python>;=2.7或>;=3.5。
用法
fromtinynetrcimportNetrcnetrc=Netrc()# parse ~/.netrc# Get credentialsnetrc['api.heroku.com']['login']netrc['api.heroku.com']['password']# Modify an existing entrynetrc['api.heroku.com']['password']='newpassword'netrc.save()# writes to ~/.netrc# Add a new entrynetrc['surge.surge.sh']={'login':'sloria1@gmail.com','password':'secret'}netrc.save()# Removing an new entrydelnetrc['surge.surge.sh']netrc.save()
您还可以使用Netrc作为上下文管理器,它将自动保存 ~/.netrc。
fromtinynetrcimportNetrcwithNetrc()asnetrc:netrc['api.heroku.com']['password']='newpassword'assertnetrc.is_dirtyisTrue# saved!
许可证
麻省理工学院许可。有关详细信息,请参阅捆绑的LICENSE文件。