Hi!
I've been working on a GUI for a while. The problem I'm currently having is that the files I'm reading in have the same "tags" for different lines.
For example, the following would be in a file I'm reading in:
[Laser1]
port ="//dev"
type ="lms"
[Laser2]
port ="//dev/s2"
type="hokuyu"
The way I read in files now uses a for loop- and I read in each line (and save things like the port information as variables that I use later in my code.)
Is there a way you can read in lines that says line+1, or something like that?
Ex of Reading in code:
for line in input:
if line[0:7] =="[Laser1]:
global laser1
laser1=StringVar()
laser1="on"
Thanks so much! Let me know if you need any more information!
gertblue
0
Newbie Poster
Recommended Answers
Jump to PostYou can use readlines() to read the entire file into a list and then access it any way you want.
input_data = open(file_name, "r").readlines() stop = len(input_data) for ctr in range(0, stop): print "This record is", ctr, input_data[ctr] if ctr+1 < stop: print "Next record is", ctr+1, …
All 3 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.