Allow Python to select strings in input files from folders

Introduction

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.

environment

・ 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

program

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

Allow Python to select strings in input files from folders
Extract strings from files in Python
Create folders from '01' to '12' with python
Manipulate files and folders in Python
Convert from Markdown to HTML in Python
[Python] Add comments to standard input files
3 ways to parse time strings in python [Note]
Convert FBX files to ASCII <-> BINARY in Python
Summary of how to import files in Python 3
From file to graph drawing in Python. Elementary elementary
How to get the files in the [Python] folder
Randomly select elements from list (array) in python
Python: Use zipfile to unzip from standard input
Key input in Python
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Key input in Python
Compare strings in Python
Reverse strings in Python
App development to tweet in Python from Visual Studio 2017
[Python] Change standard input from keyboard to text file
Import classes in jar files directly from Python scripts
How to add page numbers to PDF files (in Python)
Copy S3 files from Python to GCS using GSUtil
Things to keep in mind when processing strings in Python2
Things to keep in mind when processing strings in Python3
I want to manipulate strings in Kotlin like Python!
Post from Python to Slack
I tried to create API list.csv in Python from swagger.yaml
To flush stdout in Python
Cheating from PHP to Python
How to slice a block multiple array from a multiple array in Python
Login to website in Python
OCR from PDF in Python
Search for strings in Python
[R] [Python] Memo to read multiple csv files in multiple zip files
Python Input Note in AtCoder
Search for strings in files
2015-12-26 python2> datetime> Implementation to take the difference in seconds from two ISO format datetime strings> Use .seconds ()
How to sample from any probability density function in Python
Switch from python2.7 to python3.6 (centos7)
Speech to speech in python [text to speech]
Connect to sqlite from python
Hit REST in Python to get data from New Relic
How to develop in Python
[Python] How to use input ()
I want to make input () a nice complement in python
Post to Slack in Python
How to use functions in separate files Perl and Python versions
How to judge that the cross key is input in Python3
How to get a string from a command line argument in python
From installing Ansible to building a Python environment in Vagrant's virtual environment
Various ways to create an array of numbers from 1 to 10 in Python.
Regularly upload files to Google Drive using the Google Drive API in Python
Change the active version in Pyenv from anaconda to plain Python
Transpose CSV files in Python Part 1
[Python] How to do PCA in Python
Convert markdown to PDF in Python
Get data from Quandl in Python
How to collect images in Python
[Introduction to Python3 Day 13] Chapter 7 Strings (7.1-7.1.1.1)