![]() |
Exporting Python Output to Notepad - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: Exporting Python Output to Notepad (/thread-11822.html) |
Exporting Python Output to Notepad - Nirmal - Jul-27-2018 I have a txt file created named "commands.txt" and it contains muliple commands ( multiple lines) sh run vlan 504 sh run vlan 505 sh run vlan 700 sh run vlan 708 I want to run this against two switches and want to keep the output of the commands in a notepad.Just the raw output.My current code is def shvlan(device,child): vlans = [] with open('commands.txt', 'r') as commands: for command in commands: child.sendline(command) child.expect('.*#') vlans.extend(child.after.splitlines()) child.close() print device + ' conn closed' print 'sh run vlan executed' return vlansAny Suggestion how to do that ? RE: Exporting Python Output to Notepad - ichabod801 - Jul-27-2018 One thing you can do is write the data to a file. There is a file tutorial in the tutorial section of this board. Once you have the file, you can open it in Notepad manually, or you can open it with Python: import os with open('data.txt', 'w') as data_file: data_file.write('1 2 3 4') os.startfile('data.txt')As long as Notepad is the application associated with text files, this will open the file in Notepad. |