read input file a line as a list in python
Matteo Dell'Amico
della at toglimi.linux.it
Tue Aug 17 14:52:37 EDT 2004
Yong Wang wrote:
> Hi, All:
> I need to read a input file as soucre to process data. Ideally
> if I can read a line from input file as a list (coloumn separate by
> white space), reorganize field in a line. Does python has this kind of
> command ?
> for example, I read a line has:
> "IP MAC Date..." as a line from input file, How can I only get MAC ?
> Thanks,
>
> Yong
If I understood you correctly, this should do something like what you want:
for line in file("filename"):
ip, mac, date = line.split()
print mac
--
Ciao,
Matteo
More information about the Python-list
mailing list