read input file a line as a list in python

Y

Yong Wang

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
 
M

Matteo Dell'Amico

Yong said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top