在 Pwm 中将字符串输出为列表
Make a string output as a list in Pwm
如何将字符串输出为列表? (可能很简单,我知道)
我查看了所有 google,并且 NONE 的解决方案有效。
我的代码:(有点意译)
import Pmw
from tkinter import *
root = Tk()
console = Pmw.ScrolledText(...some arguments...)
console.pack(...some arguments...)
console.settext(os.listdir("."))
root.mainloop()
输出: file1.txt file2.txt file3.txt
在 Pmw.ScrolledText 框中。
我需要做什么才能使输出如下所示?
file1.txt
file2.txt
file3.txt
谢谢你。
使用换行符连接 os.listdir()
返回的 list
中的项目:
filenames = os.listdir('.')
text = '\n'.join(filenames)
console.settext(text)
您可以使用\n(换行符)。例如:
打印 'file1.txt\nfile2.txt\nfile3.txt'
您可以在此处找到更多信息 - https://docs.python.org/2/tutorial/inputoutput.html
如何将字符串输出为列表? (可能很简单,我知道)
我查看了所有 google,并且 NONE 的解决方案有效。
我的代码:(有点意译)
import Pmw
from tkinter import *
root = Tk()
console = Pmw.ScrolledText(...some arguments...)
console.pack(...some arguments...)
console.settext(os.listdir("."))
root.mainloop()
输出: file1.txt file2.txt file3.txt
在 Pmw.ScrolledText 框中。
我需要做什么才能使输出如下所示?
file1.txt
file2.txt
file3.txt
谢谢你。
使用换行符连接 os.listdir()
返回的 list
中的项目:
filenames = os.listdir('.')
text = '\n'.join(filenames)
console.settext(text)
您可以使用\n(换行符)。例如: 打印 'file1.txt\nfile2.txt\nfile3.txt'
您可以在此处找到更多信息 - https://docs.python.org/2/tutorial/inputoutput.html