How can I make a string output a list? (Probably very simple, I know)
I have looked through all of google, and NONE of the solutions worked.
My code: (it's a bit paraphrased)
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 box.
What do I need to do to make the output look like the following?
file1.txt
file2.txt
file3.txt
My thanks to you.
Join the items in the list
returned by os.listdir()
using a new-line character:
filenames = os.listdir('.')
text = '\n'.join(filenames)
console.settext(text)
You can use \n (new line character). for example: print 'file1.txt\nfile2.txt\nfile3.txt'
You can find more information here - https://docs.python.org/2/tutorial/inputoutput.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With