-2

I very new to Python and I want to do the following: I am creating a script that is doing for example a ssh login to devices to check all kind of things (capacity, uptime etc.) I want open a file for reading, read the first line and put every word into a variable for later use. I have been searching and trying but no result.

input file is: input.file

example: Varables are: DevType, ManuF, ip, Serial

server   Dell   172.0.0.1   abc123   
storage  IBM    172.0.0.2   w2q3r4134  
network  Cisco  172.0.0.3   vf578WWr 

Thanks for helping me out.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • Show us what you have tried so far! – Klaus D. Apr 09 '20 at 08:06
  • 1
    you can't just write the question and waiting for the code... at least write some lines – Fu Hanxi Apr 09 '20 at 08:06
  • Hello, and welcome to SO. As many users already pointed out, we encourage people to share what they've accomplished so far. This helps everybody (you included), providing effort that is on point. Please, have a read here on [how to ask a good question](https://stackoverflow.com/help/how-to-ask). – Daemon Painter Apr 09 '20 at 08:21

1 Answers1

1

open the file, iterate over lines, split() without argument to split over whitespace.

with open("input.file") as f:
    for line in f:
        dev_type, manuf, ip, serial = line.strip().split()
        print((dev_type, manuf, ip, serial))
AKX
  • 152,115
  • 15
  • 115
  • 172