IT/Programming 6

[Python] pypi-search를 통한 PyPI 패키지 정보 조회

파이썬 패키지 매니저인 Pip에서 더이상 search 서브커맨드를 지원하지 않기 때문에 특정 패키지에 대한 조회가 필요할 경우 일일이 PyPI 공식 웹사이트에 접근해야하는 불편함이 있었다. 그런데 pypi-search 패키지를 통해 더이상 그런 수고스러움을 덜 수 있게 되었다.  아래는 pypi-search 패키지를 설치 후 특정 패키지에 대한 조회 결과이다.# pypi-search 패키지 설치pip install pypi-search Collecting pypi-search Downloading pypi_search-2.0-py3-none-any.whl (7.1 kB)Collecting html2text>=2020.1.16 Downloading html2text-2024.2.2..

IT/Programming 2024.04.27

[Python] CLI 인터프리터 환경 Tab/자동 완성

Windows 환경에서 CLI 기반의 파이썬 인터프리터를 사용할 때 Tab을 이용한 자동 완성 기능이 제공되지 않아 여간 불편하지 않을 수가 없다. 다행히 이를 해결해 주는 라이브러리가 존재하는 걸 이제서야 알게 되었다-.- pyreadline3 라이브러리를 설치 후 Tab을 통해 자동 완성이 가능하다! C:\>python -m pip install pyreadline3 Collecting pyreadline3 Downloading pyreadline3-3.4.1-py3-none-any.whl.metadata (2.0 kB) Downloading pyreadline3-3.4.1-py3-none-any.whl (95 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 95.2/..

IT/Programming 2024.04.14

[Python] sorted 함수, sort 메서드 정렬 시 key 함수 활용 용례

sorted 함수와 리스트의 sort 메서드 사용 시, 매개변수로 key 함수를 별도로 지정하면 key 함수에서 리턴되는 값을 기준으로 정렬이 적용된다. >>> sorted(student_tuples, key=lambda student: student[2]) [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)] >>> sorted(student_tuples, key=lambda student: student[2], reverse=True) [('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10)] >>> student_tuples = [ ... ('john', 'A', 15), ... ('jane', 'B', ..

IT/Programming 2024.04.12

[Python] Docstring 정보 출력

클래스나 메서드, 함수 내부에 Docstring을 정의 후, help 함수 또는 __doc__ 변수를 통해 해당 정보에 대한 출력이 가능하다. >>> class Test_Class: ... """ This is Test Class """ ... def test_method(self): ... """ This is Test Method """ ... return True ... >>> help(Test_Class) Help on class Test_Class in module __main__: class Test_Class(builtins.object) | This is Test Class | | Methods defined here: | | test_method(self) | This is Test Me..

IT/Programming 2024.04.10

[Python] Dunder Method

파이썬에서 더블 언더스코어(__)로 명명되는 메서드가 무수히 존재하는데, 이를 '매직 메서드'라고 칭하고 '던더 메서드'라고 표현되기도 한다. * 참고 Python Magic methods are the methods starting and ending with double underscores ‘__’. They are defined by built-in classes in Python and commonly used for operator overloading. They are also called Dunder methods, Dunder here means “Double Under (Underscores)”. Python Magic Methods Built in classes define many ..

IT/Programming 2024.04.09

[Python] Dictionary의 값이 List 타입일 때 Append 메서드 용례

Dicionary의 특정 키에 대한 값이 List 타입일 때, List 타입에서 제공하는 Append 메서드를 활용하여 요소를 추가할 수 있다. >>> test_dict = {"a":[], "b":[]} >>> test_dict["a"].append(10,20,30) Traceback (most recent call last): File "", line 1, in TypeError: list.append() takes exactly one argument (3 given) >>> test_dict["a"].append(10) >>> test_dict["a"].append(20) >>> test_dict["a"].append(30) >>> test_dict {'a': [10, 20, 30], 'b': []..

IT/Programming 2024.04.09