본문 바로가기
반응형

python418

[Python & Flask] 플라스크를 코드 수정 시 재시작하게 하는 방법 !! (debug mode) [Python & Flask] 플라스크를 코드 수정 시 재시작하게 하는 방법 !! (debug mode) 플라스크는 그냥 시작하게 되면, 코드를 수정 할 때마다 반영사항을 보고 싶으면 종료했다가 다시 시작해야 한다. 아래와 같은 방법으로 디버그 모드 실행하면 코드 수정되면 자동으로 재시작 하게 됩니다 :) # main.py 코드안에 작성법 if __name__ == '__main__': app.run(debug=True) # 콘솔실행시 flask --app main.py --debug run 2023. 12. 3.
[Python & Django] NameError: name '_mysql' is not defined 에러 해결방법 !! [Python & Django] macOS NameError: name '_mysql' is not defined 에러 해결방법 !! 맥os에서 장고 프로젝트를 실행했는데, 장고에서 NameError: name '_mysql' is not defined 이라는 처음보는 에러가 발생하였다. 맥에선 왜이렇게 안되는게 많은걸까 ㅠㅠ 무튼 해결책을 찾아보니 config -> settings.py 에서 DATABASES쪽에 아래와 같이 작성해주시면 잘 작동 합니다 ㅎ # settings.py import pymysql pymysql.install_as_MySQLdb() DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'communi.. 2023. 11. 23.
[Python] ChatGPT API 를 활용하여 나만의 인공지능 비서만드는 방법 !! [Python] ChatGPT API 를 활용하여 나만의 인공지능 비서만드는 방법 !! openai 공식홈페이지에 있는 예시 연결하는 영상입니다. 아래코드는 영상에 나와있는 예시 코드입니다 :) https://youtu.be/h-dsZv_a7a4 본인의 API_KEY를 넣어 아래 코드 사용해주시면 됩니다 :) 예제코드 from openai import OpenAI client = OpenAI(api_key="API_KEY") completion = client.chat.completions.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "너는 인공지능 비서야. 나에게 좋은 해결책을 제시해줘."}, {"role": "user.. 2023. 11. 22.
[Python] ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 2.0.1 for xls Excel support Use pip or conda to install xlrd. 에러 해결 방법 !! [Python] ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 2.0.1 for xls Excel support Use pip or conda to install xlrd. 에러 해결 방법 !! 위 에러가 발생하였을 경우 xlrd패키지를 설치 해주면 된다 ! # pip 사용 할 경우 pip install xlrd # conda 사용 할 경우 conda install -c anaconda xlrd 2023. 11. 20.
[Python] read(), readline(), readlines() 의 사용법과 차이점 !! [Python] read(), readline(), readlines() 의 사용법과 차이점 !! 아래 사용법과 차이점에 대한 내용을 적어놨으니 확인해보세요 :) # example.txt Hello, this is the first line. This is the second line. And this is the third line. read()는 파일의 전체 내용을 문자열로 반환합니다. # example.txt 파일을 읽고 내용을 출력합니다. with open("example.txt", "r") as file: content = file.read() print(content) # 결과값 Hello, this is the first line. This is the second line. And this.. 2023. 10. 30.
[Python & Flask] 플라스크를 이용하여 html과 간단하게 호출하는 방법 !! [Python & Flask] 플라스크를 이용하여 html과 간단하게 호출하는 방법 !! 폴더 구조는 아래와 같이 해주시면 됩니다 ㅎ Project ㄴ templates ㄴ index.html ㄴ app.py 파이썬 코드 from flask import Flask, render_template, jsonify app = Flask(__name__) @app.route("/") def index(): return render_template("index.html") @app.route("/button_click", methods=["POST"]) def button_click(): # 버튼 클릭 시 실행될 로직 print("버튼이 클릭되었습니다!") return jsonify({"message": "버튼이.. 2023. 10. 26.
[Python] 파이썬으로 주사위 게임 만드는 방법 !! [Python] 파이썬으로 주사위 게임 만드는 방법 !! 코드가 간단하니 아래 코드를 응용해서 사용하시면 됩니다 :) import random class DiceGame: def __init__(self): self.player_wins = 0 self.computer_wins = 0 self.draws = 0 def roll_dice(self): return random.randint(1, 6) def play_round(self): player_roll = self.roll_dice() computer_roll = self.roll_dice() print(f"플레이어의 주사위: {player_roll}") print(f"컴퓨터의 주사위: {computer_roll}") if player_roll > .. 2023. 10. 13.
[Python & FastAPI] requests.exceptions.SSLError: HTTPSConnectionPool(host='test.co.kr', port=1105): Max retries exceeded with url: /api(Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate ve.. [Python & FastAPI] requests.exceptions.SSLError: HTTPSConnectionPool(host='test.co.kr', port=1105): Max retries exceeded with url: /api(Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])"))) 에러 해결방법 FastAPI 사용중 다른 서버 api에 호출을 하는데 이러한 에러가 발생하였다. SSLError였고, 해결 방법을 찾던 중, 초간단 해결 방법을 찾았다. verify=False 만 설정해주면 되었는데, 저는 .. 2023. 10. 11.
[Python & SQLAlchemy] orm을 사용하여 특정 인덱스 범위의 데이터를 가지고 오는 방법 !! [Python & SQLAlchemy] orm을 사용하여 특정 인덱스 범위의 데이터를 가지고 오는 방법 !! SQLAlchemy를 사용하여 특정 index범위의 데이터들을 추출하는 방법입니다 ! 예시에선 인덱스가 1부터 3까지의 데이터를 리스트로 담아오는 예시입니다 ㅎ 예제코드 # option_id 값이 1~3 사이의 값인 데이터를 추출 options = db.query(OptionDB.name).filter(OptionDB.option_id >= 1, OptionDB.option_id 2023. 10. 8.
728x90
반응형