Hello, I am new to this.
What I am trying to do is take a .txt file and write parts of it to different lists. The file contains line sof FCODE,DESCRIPTION
such as this:
DAAS44,AIRSTRIP region ruin/inactive/abandoned
I would like to split each line into FCODE and DESCRIPTION strings and append them to FCODE and DESCRIPTION lists so that I can retrieve entries in those lists later in the program.
I am reading the text file as follows:
infile = open(name, "r") lines = infile.readlines()
This gives me a list where each line seems to be a string
## create a regular expression to find all strings beginning with RR ##these represent road feature codes. reobj = re.compile("^RR[A-Z]") ## set up lists for the fcode and description fcode= desc= for line in lines: if re.search(reobj,line): fcline=line.split(",") fcode=fcline desc=fcline print desc fcode=re.split("[\b]",fcode)
What I am trying to do is split the fcode and the descriptions and get strings that each have a unique index value. While splitting the fcode and descriptions seems to work, the resulting lists only have 0,1 index values so I cant retrieve individual strings by index value.
I thought the problem might be caused by reading in the txt file all at once rather then one line at a time, but the indexing seems to work and I can take a slice of more then just [0:1] so the problem has to be with he way Im using the search regular expression.
Another thing I had considered doing beyond this is splitting the description into uppercase and lowercase sections and adding each section to its own list, however I do not know the regular expression to separate uppercase words from lowercase words and numbers.