๐ Python
10. ํ์ผ ์ ์ถ๋ ฅ
sa1t
2022. 6. 9. 10:55
๋ฐ์ํ
## ํ์ผ์ ๋ด์ฉ์ ํ(Line) ์ซ์๋งํผ ์ถ๋ ฅ
inFp = None # ์
๋ ฅ ํ์ผ ์ถ๊ธฐํ
inStr = '' # ์ฝ์ด์ฌ ๋ฌธ์์ด ์ด๊ธฐํ
inFp = open("D:\data1.txt","r",encoding="utf-8")
# ๋ณ์์ ์ด ํ์ผ ๋ด์ฉ ์ ์ฅ, r์ ์ฝ๊ธฐ๋ชจ๋, ์ธ์ฝ๋ฉ์ ์ ์ฅํ ํ์ผ์ ์ธ์ฝ๋ฉ๊ณผ ๋ง์ถฐ์ค์ผํจ
# / ์ฌ๋์ฌ 1๊ฐ \\ ์ญ์ฌ๋์ฌ 2๊ฐ (๊ฒฝ๋ก ๋ช
์ํ ๋ )
inStr=inFp.readline() # ๋ผ์ธ์ ์ฌ์ฉํด์ ํ์ค์ฉ ์ฝ๊ธฐ
print(inStr,end='')
inStr=inFp.readline()
print(inStr,end='')
inFp.close()
##### ํ์ผ์ ์๋ ๋ชจ๋ ๋ด์ฉ ์ถ๋ ฅ
inFp = None # ์
๋ ฅ ํ์ผ ์ถ๊ธฐํ
inStr = '' # ์ฝ์ด์ฌ ๋ฌธ์์ด ์ด๊ธฐํ
inFp = open("D:\data1.txt","r",encoding="utf-8")
while True :
inStr = inFp.readline()
if inStr =="":
break
print(inStr,end='')
inFp.close()
## Quiz ) ๋ผ์ธ ์ ์ผ ์์ ์ค ๋ฒํธ ๋ถ์ฌ์ ์ถ๋ ฅ
inFp = None # ์
๋ ฅ ํ์ผ ์ถ๊ธฐํ
inStr = '' # ์ฝ์ด์ฌ ๋ฌธ์์ด ์ด๊ธฐํ
i=0
inFp = open("D:\data1.txt","r",encoding="utf-8")
while True :
i=i+1
inStr = inFp.readline()
if inStr =="":
break
print("%d " %i+inStr,end='')
inFp.close()
### ํ๋ฒ์ ๋ชจ๋ ์ฝ์ด ๋ค์ด๊ธฐ
inFp = None # ์
๋ ฅ ํ์ผ ์ถ๊ธฐํ
inStr = '' # ์ฝ์ด์ฌ ๋ฌธ์์ด ์ด๊ธฐํ
inFp = open("D:\data1.txt","r",encoding="utf-8")
inStr=inFp.readlines()
print(inStr)
inFp.close()
### ํ๋ฒ์ ์ฝ์ด ๋ค์ด๊ณ ํ์ค์ฉ ์ถ๋ ฅ
inFp = None # ์
๋ ฅ ํ์ผ ์ถ๊ธฐํ
inStr = '' # ์ฝ์ด์ฌ ๋ฌธ์์ด ์ด๊ธฐํ
inList = []
inFp = open("D:\data1.txt","r",encoding="utf-8")
inList=inFp.readlines()
for inStr in inList:
print(inStr,end='')
inFp.close()
### ํ์ผ ์ํธํ ๋ฐ ์ํธ ํด๋
print(ord("์ฑ"))
# ๋ฌธ์๋ ์ซ์ ํํ๋ก ์ปดํจํฐ์ ์ ์ฅ๋๋ค
# ํ๊ธ์ ์ ๋์ฝ๋์์ ํฌํจ ๋จ
print(chr(52296))
# ์ซ์๋ฅผ ๋ฌธ์ ํํ๋ก ์ถ๋ ฅํ๋ฉด ์ฌ๋์ด ๋ณด๊ธฐ ํธํ๋ค
## ์์ ์ํธํ
# ๋จ์ํ +,- ๋ก ์ํธํ, ๋ณตํธํ
num1 = ord("์ฑ")+10
print(num1)
print(chr(num1))
# ๋ํ๊ธฐ ์ฐ์ฐ์ผ๋ก ์ํธํ
num2=num1-10
print(num2)
print(chr(num2))
# ๋นผ๊ธฐ ์ฐ์ฐ์ผ๋ก ๋ณตํธํ
num1 = (ord("์ฑ") * 2)-600
print(num1)
print(chr(num1))
num2 = int((num1+600)/2)
print(chr(num2))
#### ์ํธํ, ๋ณตํธํ ํ๋ก๊ทธ๋จ ์์ฑ
inFp, outFp = None, None
inStr, outStr = '',''
i = 0
secu = 0
secuYN = input("1.์ํธํ 2.๋ณตํธํ // ๋ฒํธ๋ฅผ ์ ํํ์ธ์ : ")
inFname = input("์
๋ ฅ ํ์ผ๋ช
์ ์
๋ ฅํ์ธ์ : ")
outFname = input("์ถ๋ ฅ ํ์ผ๋ช
์ ์
๋ ฅํ์ธ์ : ")
if secuYN == "1" :
secu = 100
elif secuYN == "2" :
secu = -100
inFp = open("d:/"+inFname, 'r', encoding='utf-8')
outFp = open("d:/"+outFname, 'w', encoding='utf-8')
while True :
inStr = inFp.readline()
if not inStr :
break
outStr = ''
for i in range(0, len(inStr)) :
ch = inStr[i]
chNum = ord(ch)
chNum = chNum + secu
# ๋ฌธ์ ์ํธํ or ๋ณตํธํ ์ฐ์ฐ
ch2 = chr(chNum)
outStr = outStr + ch2
# ์ํธํ ํ ๋ฌธ์๋ฅผ ์ ์ฅ
outFp.write(outStr)
outFp.close()
inFp. close()
print("%s ==> %s ๋ณํ ์๋ฃ" % (inFname, outFname))
# Quiz) ****.txt => ****_cipher.txt => ****_nomal.txt
# ํ์ผ ๋ช
์๋์์ฑ
# ์ํธํ ๋ณตํธํ ์๊ณ ๋ฆฌ์ฆ์ ๊ณฑํ๊ธฐ ๋๋๊ธฐ ์ฐ์ฐ ๋ค์ด๊ฐ๊ฒ
inFp, outFp = None, None
inStr, outStr = '',''
i = 0
secu = 0
cy='_cipher'
no='_nomal'
tx='.txt'
secuYN = input("1.์ํธํ 2.๋ณตํธํ // ๋ฒํธ๋ฅผ ์ ํํ์ธ์ : ")
inFname = input("์
๋ ฅ ํ์ผ๋ช
์ ์
๋ ฅํ์ธ์ : ")
outFname = input("์ถ๋ ฅ ํ์ผ๋ช
์ ์
๋ ฅํ์ธ์ : ")
if secuYN == "1" :
secu = 300/2*4
inFp = open("d:/" + inFname+tx, 'r', encoding='utf-8')
outFp = open("d:/" + outFname+cy+tx, 'w', encoding='utf-8')
elif secuYN == "2" :
secu = -300/2*4
inFp = open("d:/" + inFname+tx, 'r', encoding='utf-8')
outFp = open("d:/" + outFname+no+tx, 'w', encoding='utf-8')
while True :
inStr = inFp.readline()
if not inStr :
break
outStr = ''
for i in range(0,len(inStr)) :
ch = inStr[i]
chNum = ord(ch)
chNum = chNum + int(secu)
# ๋ฌธ์ ์ํธํ or ๋ณตํธํ ์ฐ์ฐ
ch2 = chr(chNum)
outStr = outStr + ch2
# ์ํธํ ํ ๋ฌธ์๋ฅผ ์ ์ฅ
outFp.write(outStr)
outFp.close()
inFp. close()
if secuYN=="1":
print("%s%s ==> %s%s%s ๋ณํ ์๋ฃ" % (inFname,tx,outFname,cy,tx))
else:
print("%s%s ==> %s%s%s ๋ณํ ์๋ฃ" % (inFname,tx,outFname,no,tx))
##### ์๋์ฐ ์ฐฝ ๋์ฐ๊ธฐ
from tkinter import *
window = None
canvas = None
XSIZE,YSIZE = 256,256
window = Tk()
canvas = Canvas(window, height=XSIZE, width=YSIZE)
canvas.pack()
window.mainloop()
paper = PhotoImage(width=XSIZE,height=Y)
canvas.create_image((XSIZE/2,YSIZE/2),image=paper,stat="nomal")
๋ฐ์ํ