Hi,
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 :

f=open('Test.txt','r')

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
Regards

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]
   ins+=3
   ins2+=4

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

commented: I solved my problem bcos of his help +2

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

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

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
    else:
        print "The word does not exist."

Thanks
Regards

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

Regards

well if you are happy with my help. Then try and upvote me a lil ok?
Thanks and happy coding :)

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.