gagenellina at softlab.com.ar
Tue Jan 6 02:17:30 CET 2004
At 5/1/2004 16:10, you wrote:
>I have the following information in a file :
>r1kcch Serial0/0/0 propPointToPointSerial
>Mon Jan 5 13:15:03 PST 2004 InOctets.1 0
>Mon Jan 5 13:15:05 PST 2004 OutOctets.1 0
>I want to be able to extract each line into a comma delimited list.
...into a list. The you may *show* the list in a comma-delimited format.
>Bellow i am trying to print out my list print currentList but nothing
>is comming out. I added a line after print test to make sure the file
>has the information. Can someone help me with this?
>#Read a file
>true = 1
Notice that True (capitalized) is a builtin in v2.3
>in_file = open("test.txt","r")
>text = in_file.read()
This reads the full contents of the file, and there is nothing left for the
next readline() to read... Just omit this.
> in_line = in_file.readline()
for in_line in in_file.readlines():
> if in_line == "":
> currentList = string.split(in_line,",")
There are no "," in the sample lines, just spaces.
currentList = in_line.split() # default separator is space
> #print out the contents of the current list
> print currentList
> #make the inline stop reading
> in_line = in_line[:-1]
More information about the Python-list