본문 바로가기

컴퓨터/Python

Python file 1. 파일 쓰기 with open("test.txt", "w") as file: file.write("Hello World!") 2. 파일 읽기 # 파일 열기 with open("test.txt", "r") as file: # 파일의 전체 내용을 읽어오기 content = file.read() # 읽어온 내용 출력 print(content)
Python pyinstaller 1. 설치 pip install pyinstaller 2. 빌드 pyinstaller --onefile your_script.py --onefile 옵션은 모든 필요한 라이브러리와 의존성을 하나의 실행파일로 묶어준다. 3. 실행시 콘솔창 띄우지 않기 pyinstaller --onefile --noconsole your_script.py pyinstaller --onefile --windowed your_script.py
Python tkinter ▒ 설치 tkinter 는 파이썬의 내장 모듈이므로 따로 설치할 필요가 없다. ▒ 가져오기 import tkinter as tk ▒ 창 1) 생성 window = tk.Tk() 2) 타이틀 window.title('창 이름'); 3) 크기 window.geometry("300x200") window.minsize(200, 100) window.maxsize(1820, 1080) window.resizable(False, False) ▒ 위젯 #추가 위젯.pack() #변경 위젯.config(option=value) #숨김 위젯.pack_forget() #삭제 위젯.destroy() ▒ 라벨 label = tk.Label(window, text='Hello World') ▒ 입력창 entry = tk.En..
Python Collections | 파이썬 콜렉션 Collections Ordered Changeable Indexed Duplicate List ○ ○ ○ ○ Tuple ○ × ○ ○ Set × × × × Dictionary ○ ○ ○ ×
Python tuple | 파이썬 튜플 파이썬에서 튜플(tuple)은 순서가 있는, 값의 변경이 불가능한 자료형이다. 튜플은 괄호 ()를 사용하여 생성할 수 있다. 튜플은 리스트와 달리, 값의 변경이 불가능하기 때문에 더욱 메모리 효율적이다. 또한, 리스트와 마찬가지로 튜플은 인덱싱, 슬라이싱, 연산 등을 지원한다. # Creating a tuple numbers = (1, 2, 3, 4, 5) print(numbers) # Output: (1, 2, 3, 4, 5) # Accessing elements in a tuple print(numbers[0]) # Output: 1 # Attempting to change an element in a tuple numbers[0] = 6 # Output: TypeError: 'tuple' objec..