初学python,谁能告诉我错在哪儿?
时间:2010-12-15
来源:互联网
from Tkinter import *
import os
import ConfigParser
import string
def init_listbox(listbox):
config = ConfigParser.ConfigParser()
for line in os.popen('ls ./Commands ').readlines():
config.read("Commands/" + line)
cmd_name = config.get("Inputs", "Type1")
listbox.insert(cmd_name)
dialog = Frame()
dialog.pack()
listbox = Listbox(dialog)
listbox.pack(side=TOP)
init_listbox(listbox)
Button(dialog, text='execute').pack(side=RIGHT)
dialog.mainloop()
很简单的程序,但是死活读不出ini文件内容,报no section异常。
但是我直接把文件hardcode进read(),又是对的。
不知道是哪里有问题?
import os
import ConfigParser
import string
def init_listbox(listbox):
config = ConfigParser.ConfigParser()
for line in os.popen('ls ./Commands ').readlines():
config.read("Commands/" + line)
cmd_name = config.get("Inputs", "Type1")
listbox.insert(cmd_name)
dialog = Frame()
dialog.pack()
listbox = Listbox(dialog)
listbox.pack(side=TOP)
init_listbox(listbox)
Button(dialog, text='execute').pack(side=RIGHT)
dialog.mainloop()
很简单的程序,但是死活读不出ini文件内容,报no section异常。
但是我直接把文件hardcode进read(),又是对的。
不知道是哪里有问题?
作者: magicblue 发布时间: 2010-12-15
你把os.popen('ls ./Commands ').readlines()打出来看下就知道了。
作者: iambic 发布时间: 2010-12-15
我也新手,刚刚做过实验。
for line in os.popen('ls ./Commands ').readlines():
config.read(("Commands/" + line).replace('\n', ''))
for line in os.popen('ls ./Commands ').readlines():
config.read(("Commands/" + line).replace('\n', ''))
作者: fudqpi 发布时间: 2010-12-15
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28