View Single Post
  #1  
Old 04-19-2008, 09:58 AM
Uttama_vizard Uttama_vizard is offline
Member
 
Join Date: Sep 2007
Posts: 60
Read file....many issues

I am working with a text file and trying to read it.

The text file is as follows:

Data properties:
.
.few lines
.

5 1 -1280 -1024 -1.000 -1.000 -1.000 -1.000 4 -1280 -1024 -1.000 -1.000 -1.000 -1.000 4
.
.
.
My 21st line starts with '5' as shown. From this line onwards, the data is important to me and which I want to read.

1st question:

file = open('Test.txt', 'r')
f = file.read()
print f

These lines of code prints whatever is in the text file. But, I want to selectively pick up the lines important to me (say from 21st line onwards).

2nd question:

string1 = []
string2 = []
for line in file: s = line.split() string1.append(s[0]) print string1 string2.append(s[1]) print 'abcd'
file.close()

When I am using this code, I am getting the following error message:

string1.append(s[0])
IndexError: list index out of range

But, I want to gain access to all (say about 16 strings).

Question 3:

I want to use these string values, to initiate some other actions. How do I do that.

Question 4:

I want to access this text file from another computer which is generating this data from some other application. Is there any easy way, by which I can get access to this text file on a real time basis while working in the vizard environment.

Sorry to ask so many questions...what to do...simply got stuck up in solving these issues.

If somebody can give me some valuable suggestions...that would be wonderful.

Thanks

Uttama
Reply With Quote