코딩/Python
-
[Python/Turtle] 4. Methods/Color control, Filling코딩/Python 2022. 12. 19. 21:55
빨리가기 pencolor() / fillcolor() / color() / filling() / begin_fill() / end_fill() Methods of RawTurtle/Turtle Color control turtle.pencolor(*args) 펜 색상을 반환하거나 설정 입력 포맷 pencolor() 현재 펜 색상을 색상 지정 문자열 또는 튜플로 반환 다른 color/pencolor/fillcolor 호출에 대한 입력으로 사용 pencolor(colorstring) pencolor를 "red", "yellow" 또는 "#33cc8c"와 같은 Tk 색상 사양 문자열인 colorstring으로 설정 pencolor((r, g, b)) pencolor를 r, g, b의 튜플로 표현되는 RGB 색..
-
[Python/Turtle] 3. Methods/Turtle state & Settings for measurement코딩/Python 2022. 12. 19. 21:36
빨리가기 position() / towards() / xcor() / ycor() / heading() / distance() / degrees() / radians() Methods of RawTurtle/Turtle Turtle's state turtle.position() / turtle.pos() 거북이의 현재 위치를 (x,y) (Vec2D vector)로 반환. turtle.pos() (440.00,-0.00)turtle.towards(x, y=None) x – a number or a pair/vector of numbers or a turtle instance y – a number if x is a number, else None 거북이 위치에서 (x,y)로 지정된 위치까지의 선, ..
-
[Python/Turtle] 2. Methods/Turtle motion, Pen control, More drawing control, Using events, Compound shapes코딩/Python 2022. 12. 19. 21:36
forward / back / right / left / goto;setpos;setposition / setx / sety / setheading;seth / home / circle / dot / stamp / clearstamp / clearstamps / undo / speed / pendown;pd;down / penup;pu;up / pensize / pen / isdown / reset / clear / write / onclick / onrelease / ondrag / begin_poly / end_poly / get_poly / clone / getturtle;getpen / getscreen / setundobuffer / undobufferentries / Compound shape..
-
[Python/Turtle] 1. 개요코딩/Python 2022. 12. 19. 21:36
Turtle from turtle import * color('red', 'yellow') begin_fill() while True: forward(200) left(170) if abs(pos()) < 1: break end_fill() done() 터틀은 위와 같은 그래픽을 그리게 해주는 라이브러리다. 원래는 아이들에게 코딩을 가르치기 위해 놀이용으로 개발됐다고 한다. tkinter를 기반으로 하므로 Tk를 지원하는 파이썬 버전을 사용해야 한다. TurtleScreen 클래스는 플레이그라운드인 그래팩 윈도우를 정의하는데, 이를 위해 tkinter.Canvas 또는 ScrolledCanvas가 인수로 필요하다. 터틀이 어떤 앱의 부분으로 사용되기 위해 필요하다. Screen() 함수는 TurtleSc..
-
[Python/Tip] 컬렉션 순환 중 컬렉션 객체 변경코딩/Python 2022. 12. 19. 14:35
컬렉션을 순환시키면서 특정 조건에서 컬렉션의 원소를 제거하면 순환시쿼스에 문제가 생기기 때문에, 원시 컬렉션과 별개로 순환을 위한 컬렉션을 생성시켜 순환하는 경우가 있다. collection.copy()를 사용해서 새로운 컬렉션을 생성시키지 않고 원시컬렉션의 객체를 제거할 수 있다. users = { 'A': 'active', 'B': 'inactive', 'C': 'active'} for user, status in users.copy().items(): if status == 'inactive': del users[user]
-
[Python] Webscrapping코딩/Python 2022. 12. 18. 18:30
요즘 파이썬에 대해 정리해서 어디서든 참고를 할 수 있게 블로그에 올릴 자료를 마크다운으로 정리하고 있는데, 열심히 타이핑하고 정리하다 문득 생각이 들었다. '왜 이걸 손으로 하나씩 수정하고 있지? 파이썬으로 한번에 하면 될텐데' 그래서 문구를 한번에 정리하는 유틸을 만들었다. import re fname = 'temp.txt' nfname = 'temp_new.txt' f = open(fname, 'rt') fn = open(nfname, 'at') for i in f: t = i.find('\t') title = '## ' + i[:t] desc = i[t+1:] fn.write(title + '\n') fn.write(desc + '\n'*2) f.close() fn.close() 그런데, 이걸 만..
-
Python/mac/Exif data 수정코딩/Python 2022. 11. 22. 18:27
from PIL import Image import piexif # exif data update import os img_extensions = ['.jpg', '.jpeg', '.png'] # image files having exif img = Image.open(dir_f) # image 객체 생성 # exif_dict = img.info.get('exif') # non exif -> 'None' f_exif = piexif.load(img.info['exif']) # exif 객체 생성 # exif data update img_ifd = {piexif.ImageIFD.DateTime: img_time} exif_ifd = { piexif.ExifIFD.DateTimeOriginal: img_ti..