주요 기법
데이터 파일 열기 닫기
with open( "상대경로 or 절대경로" , "r") as file: //r:읽기모드 w:쓰기모드 (기존 데이터 사라짐) a:추가모드
json 형식에서 dictionary 형식으로 변환
json.loads( file.read( ) )
dictionary 형식을 json 형식으로 전환하여 저장
json.dumps( )
콘솔 정리 함수
def clear_line():
command = "clear"
if os.name in ('nt','dos'): // 윈도우
command = "cls"
time.sleep(2)
os.system(command)
db 체크 함수
def saveuser(name,my_coin,password):
with open(" ","r") as f:
datalist = json.loads(f.read())
for data in datalist:
if(data["name"] == name):
new_info = {"name":name, "coin":my_coin, "pass":password} // 변경할 유저 정보
index = datalist.index(data) // 몇번째 index 인지
datalist[index] = new_info // 변경
with open(" ","w") as f: // 변경된 내용을 파일에 새로 씀
new = json.dumps(datalist) // 딕셔너리 형식을 json 형식으로 변환
f.write(new)
'개발 > 게임' 카테고리의 다른 글
process 다루기 (0) | 2023.12.15 |
---|---|
Web 다루기 (0) | 2023.12.15 |