1. 파이썬 기본문법
2. 데이터 조작
file io
os.path
glob
open
pickle
mariadb(mysql)
- mariadb
pip install mariadb
- 직접연결
- 데이터베이스 풀링
https://mariadb.com/docs/clients/connector-python/
- mysql
*sqlite
www.sqlite.org
https://www.sqlite.org/datatype3.html
https://sqlitebrowser.org - sqlite 브라우저
# sqlite01.py
# sqlite02.py
import sqlite3
conn = sqlite3.connect( 'test.db' )
cursor = conn.cursor()
cursor.execute( 'create table phonebook( name text, phonenum text )' )
cursor.execute( "insert into phonebook values ( 'derick', '010-111-1111' )" )
cursor.close()
print( '데이터베이스에 데이터 입력 성공' )
conn.close()
sqlbrowser로 데이터베이스 데이터 확인해보기
commit() 을 해줘야만 데이터가 들어감
sql문과 데이터부분을 나눠서 preparedStatement 구문으로 작성하기
# sqlite03.py
import sqlite3
conn = sqlite3.connect( 'test.db' )
cursor = conn.cursor()
#cursor.execute( "insert into phonebook values ( 'derick', '010-111-1111' )" )
name = 'SangJung'
phonenumber = '010-2222-2222'
sql_insert = 'insert into phonebook values( ?, ? )'
sql_data = (name, phonenumber )
cursor.execute( sql_insert, sql_data )
conn.commit() # commit()이 들어가야 데이터가 들어감
cursor.close()
print( '데이터베이스에 데이터 입력 성공' )
conn.close()
p.306 써보기
p.307~308 써보기
patch1 / patch2 예제
1. 우편번호
파일 - 데이터
2. 우편번호 검색기
'Python' 카테고리의 다른 글
Python - 15. 웹서버 (0) | 2021.03.17 |
---|---|
Python - 11. 데이터베이스 - mariaDB와 연동 (0) | 2021.03.15 |
Python - 10. 중요 모듈 (수학, 파일 입출력) (0) | 2021.03.11 |
Python - 9. 중요 모듈 (시스템, 날짜·시간 모듈) (0) | 2021.03.10 |
Python - 8. 모듈 (0) | 2021.03.10 |