Hello,


I've been looking for this here but haven't been able to find an answer that fits my case:

I have a tkinter GUI consisting in a button and a Text (a textbox). You write the whole text in the textbox, then press the button and it uses the get() method on the textbox. Now, here comes the problem: get() returns a big string, and I need a list. How do I turn the information in the textbox into a list?

I am trying to make a GUI for someone else's code. In that program, the text is not inserted into a textbox (because there's no GUI) but rather into a file. The program then uses a for statement and the readlines() method to sucessfully separate the text into smaller chunks.

The problem is that, in my case, the parsing function is getting a single string, not a list, so it's not working at all.

any help would be appreciated.

Re: Converting string to list 80 80

If the strings have newline charecters \n, try splitting the text.

s = """this is some text
this is some more text
yet some more text"""

sList = s.split()

Play around with splitting.

Re: Converting string to list 80 80

Great, it worked.

Can you explain to me what this line of code means (what the program is doing here):

if text0.strip() == text2[(text1.index(text0))].strip():
pass

particularly the part between brackets.

Re: Converting string to list 80 80

Its hard to explain.

Its basically comparing two lists.

text0 is a sting of text.

text2 is already a list.

text1 could be a list or string.

text1.index(text0) is searching text1 for the string text0; then stripping the returned results.

If the case is true, pass, or do nothing.

This wouldn't be the best way; because if text0 isn't in text1 an IndexError trace back will happen.

Does that make sense?

Re: Converting string to list 80 80

This makes a lot of sense, it is basically comparing two lines of text to see if they are the same text, if they are, the line won't be including in the merged file. Thanks to you I was able to finish the program easily. Thanks you very much.

Re: Converting string to list 80 80

EDIT: for my previews post, comparing two stings; not lists. I read the question too fast and mistaked .strip(), for .split()
They do look the same :$


So yes; comparing to strings.

And your welcome.

If you have a decent internet connection take a look at these. They talk about java; but the concepts and core ideas apply to most languages. Plus the guy giving the lectures is kinda entertaining.

Re: Converting string to list 80 80

That's prety useful, as I'm also learning Java. Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.