반응형
반응형
python - setuptool, setup.py

python.flowdas.com/install/index.html

 

파이썬 모듈 설치 (레거시 버전) — 파이썬 설명서 주석판

소개 파이썬 2.0에서, distutils API가 처음으로 표준 라이브러리에 추가되었습니다. 이는 리눅스 배포 관리자에게 파이썬 프로젝트를 리눅스 배포 패키지로 변환하는 표준 방법을 제공하고, 시스템

python.flowdas.com

python setup.py install


모듈 의존성 관리 — install_requires
비공개 모듈 설치 — dependency_links
콘솔 스크립트 설치 — entry_points
개발 모드 디플로이 — setup.py develop

 

setup.py

from setuptools import setup, find_packages

setup_requires = [
    ]

install_requires = [
    'django==1.6b4',
    'markdown==2.3.1',
    'pyyaml==3.10',
    'pillow==2.1.0',
    'lxml==3.2.3',
    'beautifulsoup4==4.3.1',
    ]

dependency_links = [
    'git+https://github.com/django/django.git@stable/1.6.x#egg=Django-1.6b4',
    ]

setup(
    name='Flowdas-Books',
    version='0.1',
    description='Flowdas Books',
    author='Flowdas',
    author_email='spammustdie@flowdas.com',
    packages=find_packages(),
    install_requires=install_requires,
    setup_requires=setup_requires,
    dependency_links=dependency_links,
    scripts=['manage.py'],
    entry_points={
        'console_scripts': [
            'publish = flowdas.books.script:main',
            'scan = flowdas.books.script:main',
            'update = flowdas.books.script:main',
            ],
        },
    )

www.flowdas.com/blog/%ED%8C%8C%EC%9D%B4%EC%8D%AC-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8-%EC%8B%9C%EC%9E%91%ED%95%98%EA%B8%B0-setuptools/

 

파이썬 프로젝트 시작하기 - Setuptools — flowdas

 

www.flowdas.com

 

반응형
반응형

Remove Elements From A Counter

 

counter에서 요소 삭제하기

Question:

How do you remove an element from a counter?

Answer:

Setting a count to zero does not remove an element from a counter. Use del to remove it entirely.

Source: (example.py)

from collections import Counter
 
c = Counter(x=10, y=7, z=3)
print(c)
 
c['z'] = 0
print(c)
 
del c['z']
print(c)

Output:

$ python example.py
Counter({'x': 10, 'y': 7, 'z': 3})
Counter({'x': 10, 'y': 7, 'z': 0})
Counter({'x': 10, 'y': 7})
반응형
반응형

How to add or increment single item of the Python Counter class

 

How to add or increment single item of the Python Counter class

A set uses .update to add multiple items, and .add to add a single one. Why doesn't collections.Counter work the same way? To increment a single Counter item using Counter.update, you have to add i...

stackoverflow.com

python 에서  Counter 증가시키명서 리스트 적용하기. 

>>> c = collections.Counter(a=23, b=-9)

#You can add a new element and set its value like this:

>>> c['d'] = 8
>>> c
Counter({'a': 23, 'd': 8, 'b': -9})


#Increment:

>>> c['d'] += 1
>>> c
Counter({'a': 23, 'd': 9, 'b': -9} 


#Note though that c['b'] = 0 does not delete:

>>> c['b'] = 0
>>> c
Counter({'a': 23, 'd': 9, 'b': 0})


#To delete use del:

>>> del c['b']
>>> c
Counter({'a': 23, 'd': 9})
Counter is a dict subclass
반응형
반응형

Yes Cyber solution is best.

For beginners

  1. Read file in Read mode.
  2. Iterate lines by readlines() or readline()
  3. Use split(",") method to split line by '
  4. Use float to convert string value to float. OR We can use eval() also.
  5. Use list append() method to append tuple to list.
  6. Use try except to prevent code from break.
My text file is:

-34.968398,-6.487265
-34.969448,-6.488250
-34.967364,-6.492370
-34.965735,-6.582322


Code:

p = "/home/vivek/Desktop/test.txt"
result = []
with open(p, "rb") as fp:
    for i in fp.readlines():
        tmp = i.split(",")
        try:
            result.append((float(tmp[0]), float(tmp[1])))
            #result.append((eval(tmp[0]), eval(tmp[1])))
        except:pass

print result


Output:

$ python test.py 
[(-34.968398, -6.487265), (-34.969448, -6.48825), (-34.967364, -6.49237), (-34.965735, -6.582322)]

Read file as a list of tuples, 파일읽어서 튜플 만들기

 

 

반응형
반응형

Sublime Text 3에서 Python 프로그래밍을 하기 위해 필요한 설정을 다루고 있습니다.

 

webnautes.tistory.com/454

 

Sublime Text 3와 함께 Python 프로그래밍(Windows / Ubuntu)

Sublime Text 3에서 Python 프로그래밍을 하기 위해 필요한 설정을 다루고 있습니다. 1. Python 설치 2. Sublime Text 3 설치 3. Sublime Text 3 기본 사용방법 4. Package Control 5. sublimeREPL 플러그인 설치..

webnautes.tistory.com

 

반응형
반응형

API 신청 - 보건복지부_코로나19 감염_현황 XML

www.data.go.kr/tcs/dss/selectApiDataDetailView.do?publicDataPk=15043376

 

공공데이터 포털

국가에서 보유하고 있는 다양한 데이터를『공공데이터의 제공 및 이용 활성화에 관한 법률(제11956호)』에 따라 개방하여 국민들이 보다 쉽고 용이하게 공유•활용할 수 있도록 공공데이터(Datase

www.data.go.kr

코로나19감염증으로 인한 일별 확진자,완치자,지료중인환자,사망자등에 대한 현황자료(이 제공자료는 관련 발생 상황에 대한 정보를 신속 투명하게 공개하기 위한 것으로, 추가적인 역학조사 결과 등에 따라 수정 및 보완될 수 있음을 알려드립니다.)

 

코로나19감염증으로 인한 일별 확진자, 완치자, 치료중인환자, 사망자등에 대한 현황자료

요청변수(Request Parameter)

항목명(국문)항목명(영문)항목크기항목구분샘플데이터항목설명

서비스키 ServiceKey 4 필수 - 공공데이터포털에서 받은 인증키
페이지 번호 pageNo 4 옵션 1 페이지번호
한 페이지 결과 수 numOfRows 4 옵션 10 한 페이지 결과 수
데이터 생성일 시작범위 startCreateDt 30 옵션 20200310 검색할 생성일 범위의 시작
데이터 생성일 종료범위 endCreateDt 30 옵션 20200315 검색할 생성일 범위의 종료

출력결과(Response Element)

항목명(국문)항목명(영문)항목크기항목구분샘플데이터항목설명

결과코드 resultCode 2 필수 00 결과코드
결과메시지 resultMsg 50 필수 OK 결과메시지
한 페이지 결과 수 numOfRows 4 필수 10 한 페이지 결과 수
페이지 번호 pageNo 4 필수 1 페이지번호
전체 결과 수 totalCount 4 필수 3 전체 결과 수
게시글번호(감염현황 고유값) SEQ 30 필수 74 게시글번호(감염현황 고유값)
기준일 STATE_DT 30 필수 20200315 기준일
기준시간 STATE_TIME 30 필수 00:00 기준시간
확진자 수 DECIDE_CNT 15 필수 8162 확진자 수
격리해제 수 CLEAR_CNT 15 필수 834 격리해제 수
검사진행 수 EXAM_CNT 15 필수 16272 검사진행 수
사망자 수 DEATH_CNT 15 필수 75 사망자 수
치료중 환자 수 CARE_CNT 15 필수 7253 치료중 환자 수
결과 음성 수 RESUTL_NEG_CNT 15 필수 243778 결과 음성 수
누적 검사 수 ACC_EXAM_CNT 15 필수 268212 누적 검사 수
누적 검사 완료 수 ACC_EXAM_COMP_CNT 15 필수 251940 누적 검사 완료 수
누적 환진률 ACC_DEF_RATE 30 필수 3.2396602365 누적 환진률
등록일시분초 CREATE_DT 30 필수 2020-03-15 10:01:22.000 등록일시분초
수정일시분초 UPDATE_DT 30 필수 null 수정일시분초

샘플코드

/* Javascript 샘플 코드 */


var xhr = new XMLHttpRequest();
var url = 'http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19InfStateJson'; /*URL*/
var queryParams = '?' + encodeURIComponent('ServiceKey') + '='+'서비스키'; /*Service Key*/
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /**/
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('10'); /**/
queryParams += '&' + encodeURIComponent('startCreateDt') + '=' + encodeURIComponent('20200310'); /**/
queryParams += '&' + encodeURIComponent('endCreateDt') + '=' + encodeURIComponent('20200315'); /**/
xhr.open('GET', url + queryParams);
xhr.onreadystatechange = function () {
    if (this.readyState == 4) {
        alert('Status: '+this.status+'nHeaders: '+JSON.stringify(this.getAllResponseHeaders())+'nBody: '+this.responseText);
    }
};

xhr.send('');
반응형

+ Recent posts