|
#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
Read File....some issues
If we use
import linecache then, we use q =linecache.getline('Test.txt', 22) print q This prints the line 22 selectively from the bulk of data. This answers the first question. If somebody can help in solving the other 3, that would be wonderful. Thanks Uttama |
#3
|
|||
|
|||
Read File....many issues
The text file missed some of the lines....so there was an error. The problem is solved.
But, the problem that still remains is the fourth question. Accessing a text file from a remote computer which is generating the text files. I want to access it while I am working in the vizard environment (in a different computer) on a real time basis. Thanks Uttama |
#4
|
|||
|
|||
You can open a file any time while your script is running. If the file is being updated at a certain rate, then you can setup a timer in Vizard that will open the file and read the contents.
|
#5
|
|||
|
|||
Hello,
Yes, I am trying to open a txt file many times and read its contents. But, I am facing a typical problem. My application is to sense the repeated pressing of a particular key of the keyboard. What I am doing is, each time I am sending a letter and writing to the txt file (response1.txt) and then trying to open the file in the read mode to read its contents. When I am using these lines at the beginning of my program (outside all loops), I am being able to read the .txt file but, not its updated contents. file5 = open('response1.txt', 'w') file6 = open('response1.txt', 'r+') When I am trying to close the file and open it within a loop such as : while count<1: vizact.onkeydown('e',InstructionScreenOFF) #Do an action on 'e' key press yield viztask.waitTime(10) file6 = open('response1.txt', 'r+') I am getting the error message.................. TypeError: 'ActionData' object is not callable Without opening the file .txt multiple times within the program, I cannot access its updated contents....and there I am getting into trouble. If somebody can suggest me any solution for this.....it would be really helpful to me. Thanks Uttama |
#6
|
|||
|
|||
Can you post the full traceback of your error? Python errors are usually very descriptive and will tell you exactly which line of code caused the error.
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Could not find plugin to load objects... | halley | Vizard | 1 | 05-30-2006 12:01 PM |
file input | vsully | Vizard | 1 | 12-21-2004 11:51 PM |
avatar head texture issues | rconrey | Vizard | 3 | 11-17-2004 05:05 PM |
Closing file handles from within function | FlyingWren | Vizard | 1 | 10-01-2003 07:02 PM |
I cannot show wrl file with text node | sled | Vizard | 3 | 06-25-2003 08:52 AM |