Reading a configuration file

Reading a configuration file

Postby frankBT » Wed Jun 29, 2016 11:52 pm

Hi Guys,
new here and new to python.
I have a configuration file of a network device and I want to print some parts of the content of that file with a python script.
I open the file with myfile = open('techsupport.txt', 'r')

but I'm not sure how to get the output from that file that includes the section of the "show version". which is more than one line of output when I did this:
Code: Select all
showversion = "show version"
for line in myfile:
    if showversion in line:
        print line


it only print the line that has show version and not the following lines.
Hopefully I am making sense and someone can help me.
Last edited by micseydel on Wed Jun 29, 2016 11:55 pm, edited 1 time in total.
Reason: Initial post lock.
frankBT
 
Posts: 1
Joined: Wed Jun 29, 2016 11:46 pm

Re: Reading a configuration file

Postby Ofnuts » Thu Jun 30, 2016 6:47 pm

We can't answer for you. How do you know which of the following lines should be printed.? Fixed number? Keyword on last line printed or on the first non-printed line?
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987


Return to Networking

Who is online

Users browsing this forum: No registered users and 3 guests

cron