使用Python的netrc文件处理
python中的netrc类用于从用户家庭环境的unix系统中的.netrc文件中读取数据。这些是隐藏文件,包含用户的登录凭据详细信息。这对于ftp,curl等工具成功读取.netrc文件并将其用于操作很有帮助。
以下程序显示了如何使用python的netrc模块读取.netrc文件。
示例
import netrc
netrc = netrc.netrc()
remoteHostName = "hostname"
authTokens = netrc.authenticators(remoteHostName)
#打印访问令牌
print("Remote Host Name:%s" % (remoteHostName))
print("User Name at remote host:%s" % (authTokens[0]))
print("Account Password:%s" % (authTokens[1]))
print("Password for the user name at remote host:%s" % (authTokens[2]))
#打印宏
macroDictionary = netrc.macros
print(macroDictionary)运行上面的代码给我们以下结果-
输出结果
Remote Host Name:hostname User Name at remote host:xxx Account Password: XXX Password for the user name at remote host:XXXXXX
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短