我目前有从用户选择的文件中读取原始内容的代码:
def choosefile():
filec = tkFileDialog.askopenfile()
# Wait a few to prevent attempting to displayng the file's contents before the entire file was read.
time.sleep(1)
filecontents = filec.read()
但是,有时人们打开大文件需要2秒钟以上才能打开。是否有FileObject.read([size])
的回调?对于不知道回调是什么的人来说,它是在执行另一个操作后执行的操作。在
问题解决答案
嗯,一开始我犯了个错误。
tkFileDialog.askopenfile()
不读取文件,但FileObject.read()
读取文件,并阻止代码。我根据@kindall找到了解决方案。不过,我不是Python的专家。在谢谢你!解析代码:
根据文件稍作修改:
相关问题 更多 >
编程相关推荐