목록프로그래밍/Python (37)
Self-Improvement
https://www.crummy.com/software/BeautifulSoup/bs4/doc/ *import1from bs4 import BeautifulSoup cs *기본 사용법 1 123456789101112131415soup = BeautifulSoup(resp, 'html.parser') print(soup.prettify()) - response 내요을 보기좋게 출력됨 soup.title soup.title.name soup.title.string soup.p soup.p['class'] soup.a - a 태그 하나만 출력 soup.find_all('a') - a 태그 전체 출력 soup.find(id="link3") - id="link3"으로 되어있는거 찾아서 출력 cs *기본 사용법 ..
*requests 패키지 설치 pycharm에서 file -> settings -> Project interpreter -> requests 패키지 검색 및 설치 (urllib3, requests, idna, chardet, certifi 가 설치됨) *requests import 1import requests cs *requests 메소드 사용법 123456789 -http://docs.python-requests.org/en/master/user/quickstart/ r=requests.get('https://api.github.com/events') - GET 메소드 r=requests.post('http://httpbin.org/post', data = {'key':'value'}) - POST ..
*플라스크 웹앱 hello_flask.py 예제 ※플라스크란 웹 프레임워크이다. 윈도우에서 작성함----------------------------------------- from flask import Flask #flask 모듈에서 Flask 클래스를 임포트한다. from vsearch import search4letters #4장에서 만들었던 vsearch 모듈에서 search4letters을 임포트했다. app = Flask(__name__) #Flask 객체의 인스턴스를 만들고 app에 할당 ※__name__ 이란 Flask 객체를 만들때 현재 버전의 __name_을 받아야한다. @app.route('/') #@app는 함수장식자로써 기존 함수의 코드를 바꾸지 않고도 함수의 동작을 조정할 수 있..
*vsearch.py 모듈 정의 예제 linux에서 작성함-------------------------------------------------- #! /usr/bin/python3 #phrase는 string이며 호출코드로 집합을 반환한다.(어노테이션) def search4vowels(phrase: str) -> set: """Returns the set of vowels found in 'phrase'.""" #docstring이라하여해당 함수의 설명문이다. return set('aeiou').intersection(set(phrase)) #set()으로 집합을 만들며 인자로받은 phrase와의 교집합하여 return으로 반환한다. #phrase는 string, letters의 인자는 string이..
*리스트 리스트를 기본 복사를하면 같은 자원을 공유하게됨 second = first second와 first의 값이 복사가 되어진것 같지만 second 리스트에 값을 넣고 확인하면 first에도 값이 같이 들어가게 되어 공유가 되어진 것이다. 리스트를 복사를 할 경우에는 copy()라는 함수를 사용하면 되어진다. *딕셔너리 딕셔너리의 데이터는 순서가 없으며 키값을 이용하여 찾는다. 딕셔너리를 포함하는 딕셔너리 people['ford']={ 'name': 'ford prefece', 'Gender': 'male'} people['ford']['name'] 하면 ford의 들어있는 name 값이 출력됨 *집합 집합은 중복을 허용하지 않으며 삽입 순서를 유지하지 않는다 vowels = {'a', 'a', 'b..
*vowels.py예제 ------------------------------------- #! /usr/bin/python3 vowels = ['a', 'e', 'i', 'o', 'u'] word = input("word : ") #키보드로 받는다 found =[] #빈 리스트를 생성 for letter in word: #word변수의 내용 한글자씩 letter에게 할당이되어 반복한다 if letter in vowels: #word한테 할당받은 letter이 vowels에 존재하는지 if letter not in found: #found에 존재하지 않으면 리스트에 추가 found.append(letter) for vowel in found: #found의 내용을 하나씩 할당하여 출력 print(vowe..
*odd.py 예제 linux에서 입력한 사진----------------------odd.py------------------- #! /usr/bin/python3 from datetime import datetime #라이브러리 와 해당 서브 모듈 odds = [1, 3, 5, 7, 9] #리스트(배열) right_this_minute = datetime.today().minute #호출로 만들어진 값이 변수에 할당 #right_this_minute가 odds 리스트에 포함되는지의 if문 if right_this_minute in odds: print("This minute seems a little odd.") else: print("Not an odd minute.") ---------------..