Programming

    ๋ฌธ์ž์—ด ๋‹ค๋ฃจ๊ธฐ

    1. ์„ ์–ธ ๋ฐ ์ฃผ์„ #๋ฌธ์ž์—ด์„ ์„ ์–ธํ•  ๋•Œ๋Š” ๋”ฐ์˜ดํ‘œ( ' ), ์Œ๋”ฐ์˜ดํ‘œ( " )๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ ๋‘˜์„ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Œ >>> test1 = "eunhye" >>> print(test1) eunhye >>> test2 = 'eunhye' >>> print(test2) eunhye >>> test3 = "eunhye' File "", line 1 test3 = "eunhye' ^ SyntaxError: EOL while scanning string literal #ํŠน์ • ๋ฌธ์ž ์ถœ๋ ฅ์„ ์œ„ํ•ด์„œ๋Š” ์ด์Šค์ผ€์ดํ”„ ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉ >>> test = 'hi\ni\'m eunhye' >>> print(test) hi i'm eunhye ์ด์Šค์ผ€์ดํ”„ ๋ฌธ์ž ์ถœ๋ ฅ ๋ฌธ์ž \' ๋”ฐ์˜ดํ‘œ( ' ) \" ์Œ๋”ฐ์˜ดํ‘œ( " ) \t ํƒญ (tab) \..

    selenium ํ†ตํ•ด์„œ web crawling ํ•ด์„œ slack ๋ฉ”์„ธ์ง€ ๋ณด๋‚ด๊ธฐ

    1. selenium, schedule, requests ์„ค์น˜ - selenium : ์›น ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ์ œ์–ดํ•œ๋‹ค. ๋ธŒ๋ผ์šฐ์ €์— ์ง์ ‘ ์ ‘๊ทผํ•˜๋‹ˆ ๋™์  ์›น ํŽ˜์ด์ง€๋„์— ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค. - reqeusts : ์ธํ„ฐ๋„ท์—์„œ ํŒŒ์ผ๊ณผ ์›น ํŽ˜์ด์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œ ๊ฐ€๋Šฅํ•˜๋‹ค. - schedule : ํŠน์ • ์ž‘์—…์„ ์ผ์ •์— ๋งž์ถฐ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ • ๊ฐ€๋Šฅํ•˜๋‹ค. - beautifulsoup : ์›น ํŽ˜์ด์ง€๋ฅผ ์ž‘์„ฑํ•˜๋Š” ํ˜•์‹์ธ HTML์„ ๊ตฌ๋ฌธ ๋ถ„์„ํ•˜๋ฉฐ ์ •์  ์›น ํŽ˜์ด์ง€๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค. (์ œ๊ฐ€ ํฌ๋กค๋ง ํ•  ์›น ํŽ˜์ด์ง€๋Š” ๋™์  ์›น ํŽ˜์ด์ง€๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— selenium์„ ์‚ฌ์šฉํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿค”) pip3 install selenium pip3 install requests pip3 install schedule 2. ํŠน์ • URL์˜ HTML ..

    ํŒŒ์ผ ๊ฒฝ๋กœ ์ด๋™(copy, move)ํ•˜๊ณ  ์‚ญ์ œ(rm)ํ•˜๊ณ  ์••์ถ•(zip)ํ•˜๊ธฐ

    1. shutil ๋ชจ๋“ˆ ์‚ฌ์šฉํ•˜๊ธฐ - copy(), move() >>> import shutil, os >>> os.chdir('/Users/eunhye/Desktop/Workspace') #shutil.copy() : source๋ฅผ destination์— ๋ณต์‚ฌ #shutil.copy(source, destination) >>> shutil.copy('A.txt', './Test') './Test/A.txt' #destination ์ด๋ฆ„์€ ์œ ์ง€๋˜๊ณ  ๋‚ด์šฉ์ด source ๋ณต์‚ฌ >>> shutil.copy('B.txt', './Test/AA.txt') './Test/AA.txt' #shutil.copytree() : ๋””๋ ‰ํ† ๋ฆฌ ํ†ต์ฑ„๋กœ ๋ณต์‚ฌ >>> shutil.copytree('.', '../Workspace_Ba..

    ํŒŒ์ผ ์—ด๊ณ (open) ์ฝ๊ณ (read) ์“ฐ๊ธฐ(wirte)

    1. open() #open() : ํŒŒ์ผ ์—ด๊ธฐ >>> path = '/Users/eunhye/Desktop/Workspace/test.txt' >>> file = open(path) 2. read() #read() : ํŒŒ์ผ ์ฝ๊ธฐ #ํ…์ŠคํŠธ ํ˜•์‹์œผ๋กœ ํ•œ์ค„์— ๋ณด์—ฌ์คŒ >>> fileContent = file.read() >>> fileContent 'test' #readlines() : ํ•œ์ค„์‹ ํŒŒ์ผ ์ฝ๊ธฐ #๋ฆฌ์ŠคํŠธ ํ˜•์‹์œผ๋กœ ๋ณด์—ฌ์คŒ >>> numberFile = open(path2) >>> numberContent = numberFile.read() >>> numberContent '1\n2\n3\n4\n5\n' >>> numberFile = open(path2) >>> numberFile.readlines() [..

    OS ๋ชจ๋“ˆ

    1. OS ๋ชจ๋“ˆ - ์šด์˜์ฒด์ œ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ๋ชจ๋“ˆ >>> import os 2. OS ํ•จ์ˆ˜ #os.path.join : ๊ฒฝ๋กœ dir/ํŒŒ์ผ์„ ๋„ฃ์„ ๊ฒฝ์šฐ OS์— ๋งž๊ฒŒ ๊ฒฝ๋กœ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ #Windows OS์—์„œ๋Š” '\\' Linux OS์—์„œ๋Š” '/'๋กœ ๊ตฌ๋ถ„ >>> os.path.join('Users', 'eunhhye', 'Desktop') 'Users/eunhhye/Desktop' #os.getcwd : ํ˜„์žฌ ๊ฒฝ๋กœ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ >>> os.getcwd() '/Users/eunhye' #os.chdir : ๊ฒฝ๋กœ๋ฅผ ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•œ ํ•จ์ˆ˜ >>> os.chdir('Desktop') >>> os.getcwd() '/Users/eunhye/Desktop' >>> os.makedirs('Workspace'..

    ์›น ํฌ๋กค๋ง(BeautifulSoup)

    1. BeautifulSoup ์„ค์น˜ - ์—ฌ๊ธฐ์„œ BeautifulSoup์€ ๋ฌด์—‡์ธ๊ฐ€? ์˜ˆ์œ ์Šพ...? HTML ๋ฐ XML ํŒŒ์ผ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ ์˜ค๊ธฐ์œ„ํ•œ Python ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค ์–ด์›์€ '์ด์ƒํ•œ ๋‚˜๋ผ์˜ ์•จ๋ฆฌ์Šค'์—์„œ ์œ ๋ž˜๋˜์—ˆ๋‹ค๊ณ  ํ•˜๊ณ  ์•„๋ฆ„๋‹ต๊ฒŒ ์ •๋ ฌํ•ด์ค€๋‹ค๋Š” ์ •๋„์˜ ์˜๋ฏธ?! Beautiful Soup Documentation — Beautiful Soup 4.9.0 documentation Non-pretty printing If you just want a string, with no fancy formatting, you can call str() on a BeautifulSoup object (unicode() in Python 2), or on a Tag within it: str(soup) # ' ..

    Codility - Lesson 4 - 2. MaxCounters

    Task Description You are given N counters, initially set to 0, and you have two possible operations on them: increase(X) − counter X is increased by 1, max counter − all counters are set to the maximum value of any counter. A non-empty array A of M integers is given. This array represents consecutive operations: if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X), if A[K] = N + 1 t..

    Codility - Lesson 4 - 1. FrogRiverOne

    Task Description A small frog wants to get to the other side of a river. The frog is initially located on one bank of the river (position 0) and wants to get to the opposite bank (position X+1). Leaves fall from a tree onto the surface of the river. You are given an array A consisting of N integers representing the falling leaves. A[K] represents the position where one leaf falls at time K, meas..

    Codility - Lesson 3 - 3. TapeEquilibrium

    Task Description A non-empty array A consisting of N integers is given. Array A represents numbers on a tape. Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1]. The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])| In other words, it is th..

    Codility - Lesson 3 - 2. PermMissingElem

    Code Description An array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing. Your goal is to find that missing element. Write a function: def solution(A) that, given an array A, returns the value of the missing element. For example, given array A such that: A[0] = 2 A[1] = 3 A[2] = 1 A[3] = 5 the ..

    Codility - Lesson 3 - 1. FrogJump

    Task description A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D. Count the minimal number of jumps that the small frog must perform to reach its target. Write a function: def solution(X, Y, D) that, given three integers X, Y and D, retur..

    Codility - Lesson 2 - 1. CyclicRotation

    Task description An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place). The goal is to rotate array A K times; that ..

    Codility - Lesson 1 - 1. BinaryGap

    Task description A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The numbe..