파이썬

ProjectDict

HTMLImgRelocater 개발기 - 파이썬 실행 파일 배포하기

HTMLImgRelocater 개발과정과 파이썬 실행 파일 배포하는 방법에 대한 글입니다. 제작 동기 구글 독스로 작업을 하던 중 인디자인에서의 이미지 링크 작업을 위해 원본 이미지 파일들을 정렬할 필요가 있었다. 그래서 html파일에 언급된 순서대로 사진에 번호를 붙여 넘버링을 하는 간단한 파이썬 코드를 작성하여 활용하였다. import os import re import shutil import urllib.parse #다운로드한 html파일의 이름 ex) index.html HTML_FILE_NAME="index.html" #다운로드한 이미지 폴더의 이름 ex) images IMAGES_FOLDER_NAME="images" RELOCATED_FOLDER_NAME="Relocated_images" #..

BugDict/Python

[Python] "AttributeError: 'NoneType' object has no attribute 'click'" 해결

문제상황: 파이썬을 사용하여 웹 자동화 툴을 개발하던 중, 웹 페이지의 특정 버튼을 클릭하려 했지만 에러가 발생했습니다. Selenium을 사용한 코드에서 에러가 발생했습니다. 아래는 에러가 발생한 코드입니다. from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome(executable_path="chromedriver_path") driver.get("https://example.com/login") username_input = driver.find_element(By.ID, "username") password_input = driver.find_element(By.ID, "p..

BugDict/Python

[Python] "AttributeError: 'NoneType' object has no attribute 'shape'" 해결

문제상황: 머신러닝 모델 개발 중 데이터 전처리 과정에서 에러가 발생했습니다. 아래 코드는 이미지 데이터를 불러와 전처리하는 과정을 담고 있습니다. import cv2 import numpy as np def load_and_preprocess_image(image_path): image = cv2.imread(image_path) image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) image = cv2.resize(image, (224, 224)) return image image_path = "example.jpg" preprocessed_image = load_and_preprocess_image(image_path) print(preprocessed_image.s..

BugDict/Python

[Python] "AttributeError: 'NoneType' object has no attribute 'method'" 해결

문제상황: 다음 코드는 실무에서 사용될 수 있는 코드로, 데이터베이스에 연결하여 테이블을 생성하는 클래스를 구현합니다. 실행 도중, "AttributeError: 'NoneType' object has no attribute 'method'" 에러가 발생했습니다. import sqlite3 class DatabaseManager: def __init__(self, db_name): self.db_name = db_name self.conn = None self.cur = None def connect(self): self.conn = sqlite3.connect(self.db_name) self.cur = self.conn.cursor() def create_table(sel..

BugDict/Python

[Python] "TypeError: can only concatenate str (not "int") to str" 해결

문제상황: 에러가 발생한 코드와 이에 대한 설명: def process_data(data, output_file): processed_data = "" for i, line in enumerate(data): processed_line = str(i) + ": " + line.strip() + " (Length: " + len(line) + ")\n" processed_data += processed_line with open(output_file, "w") as f: f.write(processed_data) input_data = ["Hello, World!", "I love Python!"] output_file = "output.txt" process_data(input_data, output_f..

Bug Detector
'파이썬' 태그의 글 목록