When analyzing data with python, when I want to make an appropriate trial and error before batch processing, it is troublesome to retype the file name each time, so I made a function that calls the folder when the input requires a file.
・ Windows 8 ・ Python3.6 ・ Anaconda 4.4.0 ・ Install wxPython by referring to the following site [Python] GUI application creation tool wxpython [Preparation]
http://qiita.com/Kodaira_/items/c073ddc400309d871150
You can write like this using wxPython. If you declare a class and use getfilename, the folder will open for each getfilename. It can be used as the return value of the function, and it is also stored in the .name which is an element of the class.
#!/usr/bin/env python
# coding:UTF-8
import wx
class FindFile():
def getfilename(self):
app = wx.App()
dialog = wx.FileDialog(None, u'Please select a file')
dialog.ShowModal()
self.name = dialog.GetPath()
return(dialog.GetPath())
if __name__ == "__main__":
f = FindFile()
f_ = f.getfilename()
print('The name of the retrieved file is',f.name,f_)
It seems that it can be used during trial and error in image processing.
Recommended Posts