Print string as a list in Pwm

How can I make a string print a list? (Probably very simple, I know)

I went through the whole google and NONE of the solutions worked.

My code: (it's a little rehash)

import Pmw from tkinter import * root = Tk() console = Pmw.ScrolledText(...some arguments...) console.pack(...some arguments...) console.settext(os.listdir(".")) root.mainloop() 

Outputs: file1.txt file2.txt file3.txt in the Pmw.ScrolledText field.

What do I need to do to make the result look like this?

 file1.txt file2.txt file3.txt 

Thanks you.

+7
python string list
source share
2 answers

Attach the items to the list returned by os.listdir() using a newline:

 filenames = os.listdir('.') text = '\n'.join(filenames) console.settext(text) 
+3
source share

You can use \ n (new line character). for example: print 'file1.txt \ nfile2.txt \ nfile3.txt'

Here you can find more information - https://docs.python.org/2/tutorial/inputoutput.html

+1
source share

All Articles