Python code below is a simple and basic code, that will open a text file in read only mode. Code below has been tested using Python3. It just demonstrates using a “print” statement to show the logic; how to open a file in read only mode and place the line that was read to a variable. The logic can be used on advance methods, such as replacing the line with IP Address and supplying a shutdown command to the IP Address. Here’s the code: #Open the file as Read Only with open('mysampledata.txt','r') as file_objHandler: #'mysampledata.txt' <--file name of the text file to be read #'r' <-- tell Python to open file as read only #Read all lines in the file. TxtLines = file_objHandler.readlines() line_counter = 0 for Oneline in TxtLines: #print(Oneline.strip()) line_counter += 1 print(line_counter, "<-- Line# / This is the data on...
Make the world a better place by sharing knowledge, ideas and anything that you can give that comes from the heart.