본문 바로가기

Programming Language/Python

(11)
pip ssl error 해결 방화벽과 프록시 등의 이슈로 pip를 이용하여 설치 등 진행 시 SSL Error가 발생하는 경우 아래와 같이 host를 신뢰하는 옵션을 주어 해결할 수 있다. 1 pip --trusted-host pypi.org --trusted-host files.pythonhosted.org install cs
Python requests InsecureRequestWarning 삭제 requests를 이용하여 SSL 요청 시 verify=False을 이용하는 경우 InsecureRequestWarning의 경고성 문구가 나타난다. 이런경우 다음과 같이 문구를 추가하면 나타나지 않는다. 예전부터 애용을 했지만, 매번 사용할 때 마다 검색하는데 이참에 블로그에 글도 남길겸 해당 내용을 작성해본다. 1 2 3 4 import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) Colored by Color Scripter cs
Python 한줄 for문 123456789101112131415161718192021222324252627282930313233343536373839404142# _*_ coding:utf-8 _*_ '''for i in [][] is iterable type data ==> string, list, tuple, dictionaryoneline for str, list, tuple, dictionary''' oneline_for_str = "".join((str(i) for i in range(5)))print(oneline_for_str) # expect result : "01234" oneline_for_list = list(i for i in range(5)) # oneline_for = [i for i in range(5..
BeautifulSoup을 이용한 파이썬 크롤링(Python Crawling with BeautifulSoup) 크롤링 대상 URL : https://stackexchange.com/leagues/ 소스코드 : https://github.com/hack-yu/Programming/blob/master/python/stack_exchange_emails_crawling.py hack-yu/Programming Contribute to hack-yu/Programming development by creating an account on GitHub. github.com
[Django] 우분투 18.04 LTS Django 설치 https://www.howtoforge.com/tutorial/how-to-install-django-on-ubuntu/ # pip3 설치하고 default로 설치되어있는 python 3.6.8 사용 (ubuntu 18은 python3이 기본으로 설치되어있음) ## ln -s /usr/bin/python3 /usr/bin/python ln -s /usr/bin/pip3 /usr/bin/pip ## pip install virtualenv pip install django ## 위의 명령어대로 하면 최신버전 장고가 설치됨. 가상환경에서 django 안정버전인 2.0.5 설치 해도됨 pip install Django==2.0.5 ## django 설치 확인 django-admin --version # 가상..
파이썬 10진수 n진수로 변환 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 def toN(n, num=2): res=[] res2='' while n>0: n, tmp = divmod(n, num) res.append((str(tmp) if tmp
Python 순열(Permutation) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 # 1 ~ n 까지의 숫자가 있을 때 나열할 수 있는 경우의 수 혹은 경우 def perm(a): length = len(a) if length == 1: return [a] else: result = [] for i in a: b = a.copy() b.remove(i) b.sort() for j in perm(b): j.insert(0, i) if j not in result: result.append(j) return result if __name__ == "__main__": num = int(input('1부터 n까지 자연수를 나열하는 순열을 구합니다. n 을 입력하세요 : ')) a..
Python itertools를 이용한 순열과 조합 (combinations, permutations) 1 2 3 4 5 6 7 8 9 10 11 12 13 import itertools abc = [1,2,3,4] #abc = ['a','b','c','d'] b = itertools.permutations(abc, 3) #target, length(Non-Essential) for i in b: #i = list(i) print(list(i)) b = itertools.combinations(abc, 2) #target, length(Essential) for i in b: #i = list(i) print(list(i))