본문 바로가기

Python7

[python] dynamically create variables as objects and associate them with specific values (e.g., worksheets) If you want to dynamically create variables as objects with names like ws_1, ws_2, and so on, and associate them with specific values (e.g., worksheets), you can use a list or a dictionary to store these objects. Here's an example using a dictionary: # Create a dictionary to store worksheet objects worksheet_dict = {} # Create and store worksheet objects for i in range(1, 6): worksheet_name = f'.. 2023. 9. 14.
python 실행 중 key input 받고 종료하기 첫번째 예) import requests import keyboard # Set up a session object to make HTTP requests session = requests.Session() # Set up a variable to store the URL to crawl url = 'https://www.example.com' # Start crawling the website while True: # Check if the user has pressed the 'q' key if keyboard.is_pressed('q'): print('Exiting program...') break # Make a request to the URL response = session.get(url) .. 2023. 4. 25.
python winsound beep 소리 내기 프로그램이 실행이 끝나면 소리로 알려 주는 코드로 사용 하면 좋을거 같다. winsound library를 이용. 1 2 3 4 5 6 7 8 9 10 11 12 def beepsound(): # 도,레,미,파,솔,라,시 Hz so1 = {'do':261,'re':293,'mi':329,'pa':349,'sol':391,'ra':440,'si':493} mel = ['do','mi','mi', 'mi','sol','sol', 're','pa','pa','ra','si','si'] dur = [4,4,2, 4,4,2, 4,4,2, 4,4,2] mel2 = ['sol','do','ra','pa','mi','do','re'] dur2 = [1,1,1,1,1,1,1] music = zip(mel,dur) mus.. 2023. 2. 4.
크롤링 checkbox 선택 및 해제 확인 하기 checkboxes = driver.find_elements(By.Name, 'xxx') for checkbox in checkboxes: if checkbox.is_selected(): #체크된 상태라면? checkbox.click() #해제 2023. 2. 2.