Python/Python

Virtualenv "가상환경" 이란? 모든 종속성과 환경변수들을 다른 소프트웨어와 구분된 파일 시스템으로 묶어둔 환경 ... ※ Python 이 설치되어 있다는 가정 하에 설치를 진행합니다. ... 1. pip 으로 간단하게 설치 $ pip install virtualenv 2. 가상 환경 생성 $ virtualenv [가상환경이름] ex) adjangotestv1이라는 이름을 갖는 가상환경 생성 3. 가상 환경 실행 $ [가상환경이름]\Scripts\activate ex) djangotestv1이라는 이름을 갖는 가상환경 실행 가상환경이 실행되면 앞에 (가상환경이름) 이 붙는다. 4. 가상 환경 종료 $ [가상환경이름]\Scripts\deactivate (수정 : 2019.06.19)한 PC에 Pyt..
pip 으로 패키지 설치하는데 아래와 같이 UnicodeDecodeError: 'ascii' codec can't decode byte 0xb9 in position 7: ordinal not in range(128)오류나는 경우 아래 두 파일의 인코딩 방식을 수정해 주면 된다. 1. Python 설치된 경로의 lib/site.py 파일에서 479490라인의 ascii를 utf-8로 변경 2. Python 설치된 경로의 lib/ntpath.py 파일에서 87라인의 result_path = result_path + p_path를 result_path = result_path + p_path.encode('utf-8')로 변경 참고한 곳: http://blog.lyuwonkyung.com/windows-pi..
# -*- coding: utf-8 -*- import pymysql pymysql.install_as_MySQLdb() conn = pymysql.connect(host='', user='', password='', db='', charset='') cursor = conn.cursor() sql=open("test.sql").read() # .sql 파일 읽음 cursor.execute(sql) cursor.fetchall() conn.close()
[Python] 특정 월의 마지막날짜 구하는 방법import calendar print calendar.monthrange(2018,1) #(0,31) print calendar.monthrange(2018,2) #(4,30) print calendar.monthrange(2018,1)[1] #31 print calendar.monthrange(2018,2)[1] #30
crontab으로 python 파일 실행시 아래와 같은 에러를 띄울 경우/usr/bin/env: python^M: No such file or directory 문제 원인 : VIM에서 (ENTER) 를 인식하지 못해 ^M ( ctrl + v + m )으로 됨.[root@aaa test]# cat -v test.py | head#!/usr/bin/env python^M# -*- coding: utf-8 -*-^M^Mfrom datetime import *^Mimport server_connect^M^Mimport logging.handlers^M# logging.basicConfig(filename='./test.log', level=logging.DEBUG)^M^M 해결 방법 : 1) ^M 제거 이때,..
List to dict list1 = [['a', 1], ['b', 2], ['c', 3]] dict1 = dict(list1) 결과dict1 = {'a': 1, 'b': 2, 'c': 3} list1 = ['hello', 'world', '1', '2'] from itertools import izipi = iter(list1)dict1 = dict(izip(i, i)) 결과dict1 = {'1': '2', 'hello': 'world'} String to dict >>> s = "{'muffin' : 'lolz', 'foo' : 'kitty'}" >>> import ast>>> ast.literal_eval(s) 결과{'muffin': 'lolz', 'foo': 'kitty'}
S0PH1A
'Python/Python' 카테고리의 글 목록 (3 Page)