MapleStory Finger Point Cute Line Smiley Blinking Hello Kitty Angel MapleStory Finger Point

πŸ’Ž Python/πŸ“šνŒŒμ΄μ¬ for Beginner (2판)

Λšβ‚Šβœ©β€§β‚Š ch 11 μ—°μŠ΅λ¬Έμ œ 풀이 - 파이썬 for Beginner (2판) Λšβ‚Šβœ©β€§β‚Š

HYEJU01 2024. 4. 8. 02:59

1. 파일 μž…μΆœλ ₯κ³Ό κ΄€λ ¨λœ ν•¨μˆ˜λ₯Ό κ³ λ₯΄μ‹œμ˜€

read(), readline(), write(),writeline(), readlines() -> "파일" μž…μΆœλ ₯ κ΄€λ ¨ ν•¨μˆ˜

input(), pirnt() λŠ” "ν‘œμ€€" μž…μΆœλ ₯ ν•¨μˆ˜μ΄λ‹€.

 

2. μ½”λ“œ λΉˆμΉΈμ„ μ±„μš°μ‹œμ˜€

inFp = fileopen("C:/Temp/data1.txt", "r", encoding="utf-8")

inStr = inFp.readline()
print(inStr,end="")

inFP.close()

 

3. λΉˆμΉΈμ„ μ±„μš°μ‹œμ˜€

inFp = open("C:/Temp/data1.txt","r"",encoding='utf-8'")

inList = inFp.readlines() #ν•œλ²ˆμ— 읽어 μ €μž₯
for inStr in inList:
    print(inStr, end="")

inFp.close()

 

4. open() ν•¨μˆ˜λ‘œ 파일 μ—†μ„λ•Œ 였λ₯˜λ°©μ§€ ν•¨μˆ˜λŠ”?

os.path.exists() ν•¨μˆ˜

 

5. λΉˆμΉΈμ„ μ±„μš°μ‹œμ˜€ (λ„μŠ€ λͺ…λ Ή copy)

inList = inFp.readlines()
for inStr in inList:
    outFp.writelines(inStr)

 

6. 이진 파일 μ½κ±°λ‚˜ μ“°λŠ”λ° μ‚¬μš©ν•˜λŠ” ν•¨μˆ˜?

ν•œλ°”μ΄νŠΈμ”© μ²˜λ¦¬ν•˜λŠ”   read(), write() ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•œλ‹€.

 

7. 각 μ„€λͺ…에 λ§žλŠ” os, os.path, shutil λͺ¨λ“ˆ ν•¨μˆ˜λ₯Ό μ“°μ‹œμ˜€.

파일 볡사 shutil.copy(μ†ŒμŠ€νŒŒμΌ,νƒ€κΉƒν•¨μˆ˜)

디렉터리 볡사 shutil.copytree( μ†ŒμŠ€νŒŒμΌ,νƒ€κΉƒν•¨μˆ˜)

디렉터리 생성 os.mkdir(폴더λͺ…)

디렉터리 μ‚­μ œ shutil.rmtree (폴더λͺ…)

폴더 μ—¬λΆ€ 확인 os.path.exists 

파일 μ‚­μ œ os.remove(파일λͺ…)

 

 

8. try~except λ¬Έμ—μ„œ μ‚¬μš©ν•˜λŠ” μ˜ˆμ™Έμ’…λ₯˜

μ—†λŠ” λ³€μˆ˜ μ ‘κ·Ό NameError

파일 μ²˜λ¦¬μ—μ„œ 였λ₯˜ λ°œμƒ IOError

μ‹€ν–‰μ—μ„œ 였λ₯˜ λ°œμƒ RuntimeError

λ”•μ…”λ„ˆλ¦¬μ— ν‚€κ°€ μ—†μŒ KeyError