Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

사용자에게 Python에서 파일을 읽을 폴더를 선택하도록 요청

<시간/>

대화 상자가 Python 애플리케이션에서 어떻게 작동하는지 궁금하다면 아마도 filedialog를 듣게 될 것입니다. Tkinter의 모듈. 파일 대화상자 모듈에는 시스템에서 파일을 처리하기 위한 다양한 유형의 대화 상자를 표시하는 데 사용할 수 있는 여러 내장 기능이 있습니다.

대부분의 경우 filedialog.askopenfilename()을 사용합니다. 사용자에게 시스템에서 파일을 찾아 열도록 요청하는 기능입니다. 파일 유형 선택에 따라 스크립트는 쓰기 또는 읽기 작업을 수행하도록 프로그래밍됩니다.

파일이 열리면 open(file, 'mode')을 사용할 수 있습니다. 모든 모드에서 작업을 열고 수행하는 기능. 이를 보여주기 위해 사용자에게 텍스트 파일을 열도록 요청하는 응용 프로그램을 만드는 예를 들어보겠습니다. 파일을 선택하고 열면 "읽기" 작동 모드를 사용하여 이 파일을 읽을 수 있습니다.

예시

# Import the library
from tkinter import *
from tkinter import filedialog

# Create an instance of window
win=Tk()

# Set the geometry of the window
win.geometry("700x300")

# Create a label
Label(win, text="Click the button to open a dialog", font='Arial 16 bold').pack(pady=15)

# Function to open a file in the system
def open_file():
   filepath = filedialog.askopenfilename(title="Open a Text File", filetypes=(("text    files","*.txt"), ("all files","*.*")))
   file = open(filepath,'r')
   print(file.read())
   file.close()

# Create a button to trigger the dialog
button = Button(win, text="Open", command=open_file)
button.pack()

win.mainloop()

출력

위의 코드를 실행하면 대화 상자를 여는 버튼이 있는 창이 표시됩니다.

사용자에게 Python에서 파일을 읽을 폴더를 선택하도록 요청

텍스트 파일을 선택하여 열면 콘솔에 파일의 모든 내용이 표시됩니다.

Centralized Database Vs Blockchain

A blockchain can be both permissionless (like Bitcoin or Ethereum) or permissioned (like the different Hyperledger blockchain frameworks). A permissionless blockchain is also known as a public blockchain, because anyone can join the network. A permissioned blockchain, or private blockchain, requires pre-verification of the participating parties within the network, and these parties are usually known to each other.

Types of Blockchains
The choice between permissionless versus permissioned blockchains should be driven by the particular application at hand (or use case). Most enterprise use cases involve extensive vetting before parties agree to do business with each other. An example where a number of businesses exchange information is supply chain management. The supply chain management is an ideal use case for permissioned blockchains.

You would only want trusted parties participating in the network. Each participant that is involved in the supply chain would require permissions to execute transactions on the blockchain. These transactions would allow other companies to understand where in the supply chain a particular item is.