পাইথনের নেটআরসি ক্লাসটি ব্যবহারকারীর হোম ফায়ারক্টরিতে ইউনিক্স সিস্টেমে উপস্থিত .netrc ফাইল থেকে ডেটা পড়ার জন্য ব্যবহার করা হয়। এগুলি লুকানো ফাইল যাতে ব্যবহারকারীর লগইন শংসাপত্রের বিবরণ থাকে। এটি এফটিপি, কার্ল ইত্যাদির মতো টুলের জন্য সহায়ক, নেটআরসি ফাইলটি সফলভাবে পড়তে এবং তাদের ক্রিয়াকলাপের জন্য এটি ব্যবহার করতে।
নিচের প্রোগ্রামটি দেখায় কিভাবে আমরা পাইথনের নেটআরসি মডিউল ব্যবহার করে .netrc ফাইলটি পড়তে পারি।
উদাহরণ
import netrc netrc = netrc.netrc() remoteHostName = "hostname" authTokens = netrc.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.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