간단한 구구단 코드를 만들어 봅시다.

for i in range(1, 10):
    for j in range(1, 10):
        print(f"{i} x {j} = {i*j}")
    print("----------")
  • for i in range(1, 10): - 이 부분은 "for" 루프를 시작하는 부분입니다. 여기서 "i"는 반복 변수로, range(1, 10) 함수에 의해 제공되는 숫자의 시퀀스를 순회합니다. 이 함수는 첫 번째 인수에서 시작하여 두 번째 인수보다 하나 작은 숫자까지의 범위를 생성합니다. 그러므로, 이 루프는 i가 1부터 9까지를 반복합니다.
  • for j in range(1, 10): - 이것은 "중첩된 for 루프"라고도 불립니다. 첫 번째 루프의 각 반복에 대해, 이 두 번째 루프는 j가 1부터 9까지 반복합니다. 이런 식으로, 모든 i와 j의 조합을 한 번씩 실행하게 됩니다.
  • print(f"{i} x {j} = {i*j}") - 이 줄은 문자열을 화면에 출력합니다. 파이썬의 f-string 문법을 사용하여 i, j, 그리고 i*j의 값을 동적으로 문자열에 포함시킵니다.
  • print("----------") - 이것은 각 구구단이 끝나면 출력되는 구분선입니다. 이는 각 숫자의 구구단 사이를 구분하기 위한 것입니다.

각 단계가 어떻게 작동하는지 이해하는데 어려움이 있으면 언제든지 질문해주세요!






 

'python' 카테고리의 다른 글

Python FTP TLS implicit  (0) 2022.09.24
How do I add comments to JSON ?  (0) 2022.09.24
Python package install ( offline )  (0) 2022.09.24
Python Install ( linux )  (0) 2022.09.24
from ftplib import FTP_TLS

class implicit_ftp(FTP_TLS):
    def __init__(self):
        FTP_TLS.__init__(self, '', '', '', '', None, None, None, 60)

    def connect(self, user, pw, timeout=-999):
        self.host = 'myhost.com'
        self.port = 990
            
        if timeout != -999:
            self.timeout = timeout

        try: 
            self.sock = socket.create_connection((self.host, self.port), self.timeout)
            self.af = self.sock.family
            self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile, ssl_version=ssl.PROTOCOL_TLSv1)
            self.file = self.sock.makefile('r')
            self.welcome = self.getresp()
            self.login(user=user, passwd=pw)
            self.prot_p()
        except Exception as e:
            print (e)

        return self.welcome

'python' 카테고리의 다른 글

구구단 - 파이썬  (0) 2023.06.03
How do I add comments to JSON ?  (0) 2022.09.24
Python package install ( offline )  (0) 2022.09.24
Python Install ( linux )  (0) 2022.09.24

기본적으로 json은 주석을 지원하지 않는 format으로 알고 있다. (필자기준)

주석을 이용하려면 pre processing 해주어야 한다.

def load(jsonpath):
	with open(jsonpath, 'r') as jsonfile:
    	# support C++ type comment
    	r = re.compile('^\s*//.*$')
        jsondata = ''.join ( l for l in jsonfile if r.match(l) is None)
        return json.loads(jsondata)
    return None

위 코드는 현재 사용하고 있는 코드인데, 라인에는 주석만 있는 것을 가정하고 작성한 코드이다.

pre processing 부분의 code를 작성해서 string list를 json.loads로 넘겨주면 되는 것이 중요한 포인트이다.

'python' 카테고리의 다른 글

구구단 - 파이썬  (0) 2023.06.03
Python FTP TLS implicit  (0) 2022.09.24
Python package install ( offline )  (0) 2022.09.24
Python Install ( linux )  (0) 2022.09.24

offline인 상태인 곳에 python package를 install 해야하는 경우가 있다.

또한 package를 업데이트 하고 싶을 수 있다.

필자는 package를 다운로드 한 다음에 offline인 서버에 package를 설치해야하는 경우였다.

아래와 같은 방법을 사용하였다.

Package Download

Offline인 곳에 설치하기 위한 package 다운로드. 아래는 tk, openpyxl package 다운로드 example

python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package tk
python -m pip download --no-binary=:all: -d ./pip-package openpyxl
  • --only-binary : binary 형태 wheel을 다운로드 할 건지
  • --no-binrary : source 코드 (압축) 다운로드 할 건지
  • --platform any : 어떤 os든 설치가능한 버전을 받을 건지
  • --platform ${MY} : 맞는 버전을 다운로드 할 것인지
    • --platform을 찾는 방법
      • https://pypi.org/에서 찾고자하는 package를 검색 및 download page로 이동
      • Build Distributions에서 선택
      • 필자의 경우 설치는 여러가지 해보고 정상설치 되는 것을 찾았다.
    • platform으로 할지 wheel로 할지.. 많은 시도를 해야할 수 있다.

아래는 필자가 현재 사용하는 package 리스트

더보기
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package tk

python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package wheel
::python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package pip

:: ---- office ----
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package xlrd
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package xlrd3
python -m pip download --no-binary=:all: -d ./pip-package openpyxl
python -m pip download --no-binary=:all: -d ./pip-package python-docx
python -m pip download --no-binary=:all: -d ./pip-package docx
python -m pip download --no-binary=:all: -d ./pip-package docxcompose

:: ---- textual ----
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package textual
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package poetry-core

:: ---- jira ----
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package setuptools-scm
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package setuptools-rust
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package flit_core
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64                -d ./pip-package SecretStorage
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64                -d ./pip-package jira

:: ---- etc ----
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package PyJWT
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package chardet
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package psutil
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package pbr
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64                -d ./pip-package numpy
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package GitPython
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package pycryptodomex
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package pycryptodome
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64                -d ./pip-package paramiko
python -m pip download --no-binary=:all: -d ./pip-package pyinstaller
python -m pip download --no-binary=:all: -d ./pip-package atlassian-python-api


python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package wheel
::python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package pip

:: ---- office ----
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package xlrd
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package xlrd3
python -m pip download --no-binary=:all: -d ./pip-package openpyxl
python -m pip download --no-binary=:all: -d ./pip-package python-docx
python -m pip download --no-binary=:all: -d ./pip-package docx
python -m pip download --no-binary=:all: -d ./pip-package docxcompose

:: ---- textual ----
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package textual
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package poetry-core

:: ---- jira ----
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package setuptools-scm
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package setuptools-rust
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package flit_core
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64                -d ./pip-package SecretStorage
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64                -d ./pip-package jira

:: ---- etc ----
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package PyJWT
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package chardet
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package psutil
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package pbr
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64                -d ./pip-package numpy
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package GitPython
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package pycryptodomex
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64 --platform any -d ./pip-package pycryptodome
python -m pip download --only-binary=:all: --platform manylinux2014_x86_64                -d ./pip-package paramiko
python -m pip download --no-binary=:all: -d ./pip-package pyinstaller
python -m pip download --no-binary=:all: -d ./pip-package atlassian-python-api

Package Install

Install은 download에 비해서 굉장히 간단하다.

python3 -m pip install --upgrade --no-index --find-links=${DOWNLOAD_DIR} ${PACKAGE_NAME}

 

'python' 카테고리의 다른 글

구구단 - 파이썬  (0) 2023.06.03
Python FTP TLS implicit  (0) 2022.09.24
How do I add comments to JSON ?  (0) 2022.09.24
Python Install ( linux )  (0) 2022.09.24

+ Recent posts