IPython Notebook: Open/select file with GUI (Qt Dialog)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When you perform the same analysis in a notebook on different data files, may be handy to graphically select a data file. In my python scripts I usually implement a QT dialog that returns the file-name of the selected file: from PySide import QtCore, QtGui def gui_fname(dir=None): """Select a file via a dialog and return the file name. """ if dir is None: dir ='./' fname = QtGui.QFileDialog.getOpenFileName(None, "Select data file...", dir, filter="All files (*);; SM Files (*.sm)") return fname[0] However, running this function from an