kyohoonsim / kusf-data-2023-1

2023-1 KUSF data 수업 강의자료 레포지토리
17 stars 1 forks source link

Quiz11. 투수 기록을 조회하는 함수를 만들어보고 활용해보자. #13

Open kyohoonsim opened 1 year ago

kyohoonsim commented 1 year ago

소스코드 및 실행결과 캡쳐 화면 제출

echoe1009 commented 1 year ago
from sqlalchemy import create_engine, text

db_connection_info = {
    'user': 'root',
    'password': 'asdf1234!',
    'host': 'localhost',
    'port': 3306,
    'database': 'lahmansbaseballdb'
}

db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}?charset=utf8"
engine = create_engine(db_url, max_overflow=0)

def read_player_pitching_data(playerID: str):
    '''선수ID를 입력받아 투수 데이터를 반환해주는 함수'''
    with engine.connect() as conn:
        rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
    row_list = [row for row in rows]
    return row_list

if __name__ == "__main__": #엔트리 포인트
    kim_pitching_data = read_player_pitching_data('kimby01')
    print(kim_pitchting_data)

image

indianaPoly commented 1 year ago

코드

def read_player_pitching_data(playerID: str):
    with engine.connect() as conn:
        rows = conn.execute(text("select * from pitching where playerID=:playerID"), {
            'playerID': playerID
        })
    row_list = [row for row in rows]
    return row_list

#Entry Point
if __name__ == "__main__":
    ryu_data = read_player_pitching_data('ryuhy01')
    for row in ryu_data:
        print(row)

출력결과

스크린샷 2023-06-28 오후 7 42 21
kyohoonsim commented 1 year ago
print("hello")

''' print("hello") '''

expediore commented 1 year ago
from sqlalchemy import create_engine, text

db_connection_info = {
    'user' : 'root',
    'password' : 'asdf1234!',
    'host' : '127.0.0.1', #localhost
    'port' : 3306,
    'database': 'lahmansbaseballdb'   
}

db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}"

engine = create_engine(db_url, max_overflow=0)

def read_player_pitching_data(playerID) :
    '''선수ID를 입력받아 피칭 데이터를 반화내주는 함수'''
    with engine.connect() as conn:
        rows = conn.execute(text("SELECT * FROM pitching WHERE playerID = :playerID"), {'playerID' : playerID})

        row_list = [row for row in rows]
        return row_list

if __name__ == "__main__" : #엔트리 포인트
    ryu_pitching_data = read_player_pitching_data('ryuhy01')
    print(ryu_pitching_data)

image

xinnazim commented 1 year ago

def read_player_pitching_data(playerID:str):
    with engine.connect() as conn:
        rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
    row_list = [row for row in rows]
    return row_list

if __name__ == "__main__": # 엔트리 포인트
    ryu_pitching_data= read_player_pitching_data('ryuhy01')
    print(ryu_pitching_data)  

스크린샷 2023-06-28 194259

aosdbfc commented 1 year ago
def read_player_batting_data(playerID: str):
    with engine.connect() as conn:
        rows = conn.execute(text("select * from batting where playerID = :playerID"), {'playerID': playerID})

    row_list = [row for row in rows]
    return row_list

def read_player_pitching_data(playerID: str):
    with engine.connect() as conn:
        rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})

    row_list = [row for row in rows]
    return row_list

if __name__ == "__main__":
    #choo_batting_data = read_player_batting_data('choosh01')
    #print(choo_batting_data)

    #kang_batting_data = read_player_batting_data('kangju01')
    #print(kang_batting_data)

    ryu_peaching_data = read_player_pitching_data('ryuhy01')
    print(ryu_peaching_data)
`

image

dhEhdod commented 1 year ago
def read_player_pitching_data(playerID: str):
    '''선수 ID를 입력받아 투구 데이터를 반환해주는 함수'''
    with engine.connect() as conn:
        rows = conn.execute(text("SELECT * FROM pitching WHERE playerID = :playerID"), {'playerID': playerID})

    row_list = [row for row in rows]
    return row_list

if __name__ == "__main__": # 앤트리 포인트
    ryu_pitching_data = read_player_pitching_data('ryuhy01')
    print(ryu_pitching_data)

image

JJungEunnn commented 1 year ago

... from sqlalchemy import create_engine, text

dict = {'키' : '값', '키': '값',}

db_connection_info = { 'user': 'root', 'password': 'asdf1234!', 'host': 'localhost', 'port': 3306, 'database': 'lahmansbaseballdb' }

db_url =f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}"

print(db_url) engine = create_engine(db_url, max_overflow=0)

def read_player_batting_data(playerID: str): with engine.connect() as conn: rows = conn.execute(text("select * from batting where playerID = :playerID"), {'playerID': playerID})

def read_player_pitching_data(playerID: str): with engine.connect() as conn: rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})

row_list = [row for row in rows]
return row_list

if name == "main": choo_data = read_player_batting_data('choosh01') print(choo_data)

kang_data = read_player_batting_data('kangju01')
print(kang_data)

pitcher_data = read_player_pitching_data('ryuhy01')
print(pitcher_data)

...

image
SHINZIMIN commented 1 year ago
from sqlalchemy import create_engine, text

db_connection_info = {
    'user': 'root',
    'password': 'asdf1234!',
    'host': 'localhost',
    'port': 3306,
    'database': 'lahmansbaseballdb'
}

db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}?charset=utf8"
engine = create_engine(db_url, max_overflow=0)

def read_player_pitching_data(playerID: str):
    '''선수 ID를 입력하면 투수 데이터 반환'''
    with engine.connect() as conn:
        rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})

    row_list = [row for row in rows]
    return row_list

if __name__ == "__main__":

    ryu_data = read_player_pitching_data('ryuhy01')
    print(ryu_data)

image

BAEKDONGSEOK commented 1 year ago

def read_player_pitching_data(playerID: str): with engine.connect() as conn: rows = conn.execute(text("select * from pitching where playerID=:playerID"), { 'playerID': playerID }) row_list = [row for row in rows] return row_list

if name == "main": ryu_data = read_player_pitching_data('ryuhy01') for row in ryu_data: print(row)

image

hungrywoo commented 1 year ago
def read_player_pitching_data(playerID: str):
    '''선수ID를 입력받아 투구 데이터를 반환해주는 함수'''
    with engine.connect() as conn:
        rows = conn.execute(text("SELECT * FROM pitching WHERE playerID = :playerID"), {'playerID': playerID})

    row_list = [row for row in rows]
    return row_list

if __name__ == "__main__": # 엔트리 포인트
    kim_pitching_data = read_player_pitching_data('kimby01')
    print(kim_pitching_data)

image

jjjjjjye commented 1 year ago
def read_player_pitching_data(playerID:str):
    '''선수 아이디를 입력받아 투수 데이터 변환해주는 함수'''
    with engine.connect() as conn:
        rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})

    row_list = [row for row in rows]
    return row_list

if __name__ == "__main__": #엔트리 포인트
    choo_batting_data = read_player_batting_data('choosh01')
    print(choo_batting_data)

    kang_batting_data = read_player_batting_data('kangju01')
    print(kang_batting_data)

    ryu_pitching_data = read_player_pitching_data('ryuhy01')
    print(ryu_pitching_data)
스크린샷 2023-06-28 195233
Y0nghwan commented 1 year ago
def read_player_pitching_data(playerID: str):
    '''선수ID를 입력받아 피칭 데이터를 반환해주는 함수'''
    with engine.connect() as conn:
        rows = conn.execute(text("SELECT * FROM pitching WHERE playerID = :playerID"), {'playerID': playerID})

    row_list = [row for row in rows]
    return row_list

if __name__ == "__main__": # 엔트리 포인트  
    ryu_pitching_data = read_player_pitching_data('ryuhy01')
    print(ryu_pitching_data)
image
KUSFTWOO commented 1 year ago
def read_player_pitching_data(playerID: str):
    '''선수ID를 입력받아 투수 데이터를 반환해주는 함수'''
    with engine.connect() as conn:
        rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
    row_list = [row for row in rows]
    return row_list

if __name__ == "__main__":
    ryu_pitching_data = read_player_pitching_data('ryuhy01')
    print(ryu_pitching_data)

image

last0331 commented 1 year ago

from sqlalchemy import create_engine, text

db_connection_info = { 'user': 'root', 'password': 'asdf1234!', 'host': 'localhost', 'port': 3306, 'database': 'lahmansbaseballdb' }

db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}?charset=utf8" engine = create_engine(db_url, max_overflow=0)

def read_player_pitching_data(playerID: str): with engine.connect() as conn: rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})

row_list = [row for row in rows]
return row_list

if name == "main":

ryu_data = read_player_pitching_data('ryuhy01')
print(ryu_data)

quiz 11

monimanimo commented 1 year ago
from sqlalchemy import create_engine, text
db_connection_info = {
    'user': 'root',
    'password': 'asdf1234!',
    'host': 'localhost', # localhost
    'port': 3306,
    'database': 'lahmansbaseballdb'
}

db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}"
engine = create_engine(db_url, max_overflow=0)

def read_player_pitching_data(playerID: str):
    with engine.connect() as conn:
        rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})

    row_list = [row for row in rows]
    return row_list

if __name__ == "__main__":
    ryu_pitching_data = read_player_pitching_data('ryuhy01')
    print(ryu_pitching_data)

image

WooJHo commented 1 year ago

from sqlalchemy import create_engine, text

db_connection_info = { 'user': 'root', 'password': 'asdf1234!', 'host': 'localhost', 'port': 3306, 'database': 'lahmansbaseballdb' }

db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:\ {db_connection_info['password']}@{db_connection_info['host']}:\ {db_connection_info['port']}/{db_connection_info['database']}?charset=utf8" engine = create_engine(db_url, max_overflow=0)

def read_player_pitching_data(playerID: str): with engine.connect() as conn: rows = conn.execute(text("select *\ from pitching where playerID = :playerID"),{'playerID' : playerID})

row_list = [row for row in rows]
return row_list

if name == "main": ryu_data = read_player_pitching_data('ryuhy01') print(ryu_data)

image