পাইথনে netrc ক্লাস ব্যবহার করা হয় ইউনিক্স সিস্টেমে ইউজার হোম ডিরেক্টরিতে থাকা .netrc ফাইল থেকে ডেটা পড়ার জন্য। এই হিডেন ফাইলগুলিতে ইউজারদের লগইন ক্রিডেনশিয়ালের ডিটেইলস থাকে। এটি ftp, curl এর মতো টুলগুলোর জন্য সাহায্যকারী যাতে সফলভাবে .netrc ফাইল পড়ে তাদের অ্যাকশন কমপ্লিট করতে পারে।
নিচের প্রোগ্রামে দেখানো হয়েছে কিভাবে পাইথনের netrc মডিউল ব্যবহার করে .netrc ফাইল পড়া যায়।
উদাহরণ
import netrc
netrc_obj = netrc.netrc()
remoteHostName = "hostname"
authTokens = netrc_obj.authenticators(remoteHostName)
# Print the access tokens
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]))
# print the macros
macroDictionary = netrc_obj.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