I am making a simple application where it reads and loads words from a text file into a ListCtrl(lc_report) in wxPython. There are only two column. i am loading it like this :


all_words = map(lambda l: l.split(" "), f.readlines())

And in Test.txt file, there are some words like this :

Devid R 21 Floor
John B 33 Floor

Now as you can see what happens when it loads the words. I can only see Devid in first column and R in second column since there are only two columns. How do make it so that Devid R will come in first column and 21 Floor will come in second column with space. I am having space problem. Any help will be appreciated.

Thanks in advance

Edited 5 Years Ago by BirdaoGwra: n/a

why dont you only read the lines into a list and slize it???

The increment the index to get what you want?

listc = [x.split() for x in f.readline()]
## now you get the data like
ins =0
ins2 =0
for x in listc:
   print listc[ins:ins2+1],listc[ins+2:ins2+3]

something like this. coming from my HTC fone.
hope you get the idea

Edited 5 Years Ago by richieking: n/a

I solved my problem bcos of his help

Can you tell me how to get the word from the user input please.

f = open("1234.txt", "r")
find = f.readlines()

word = raw_input("Type a word:")

for i, line in enumerate(find):
    if word in line: 
        for l in find[i:i+1]: print l,
        print "The word does not exist."


Ahh, its OK. I just solved it :). richieking, thanks for reply.


This article has been dead for over six months. Start a new discussion instead.