環境
- Windows 10
- Python 3.10.1
使用するソースコード
以下の公開リポジトリに置いています
GitHub - masayan1126/tao-py-py: 作業自動化用 Python ライブラリ
作業自動化用 Python ライブラリ. Contribute to masayan1126/tao-py-py development by creating an account on GitHub.
命名規則と具体例
関数名
概要
- 関数名は全て小文字
- 複数の単語を使う場合は、単語の区切りにアンダースコア(_)を使い、スネークケースとする
具体例
class XUrl:
def __init__(self, href):
self.href = href
def get_href(self):
return self.href
def get_scheme(self):
return urlparse(self.href).scheme
変数名
概要
- 変数名は全て小文字
- 複数の単語を使う場合は、単語の区切りにアンダースコア(_)を使い、スネークケースとする
具体例
# 画像URLからダウンロード
...割愛
for image_url in image_name_list:
x_url = XUrl(url=image_url)
if not CheckIsValidUrlService().execute(x_url):
exit()
x_image = XImage(src=image_url, alt="")
DownloadImageService().execute(x_image=x_image, download_path_to=download_path_to)
定数名
概要
- すべて大文字
- 複数の単語を使う場合は、単語の区切りにアンダースコア(_)を使用可能
具体例
# GithubApiを叩く準備
GITHUB_USERNAME = "masayan1126"
...割愛
モジュール名・パッケージ名
概要
- モジュール名・パッケージ名は全て小文字で記述
- 複数の単語を使う場合は、単語の区切りにアンダースコア(_)を使いスネークケースとする
具体例
packages
└file_downloader
└optimize_image_upload
shared
└check_is_valid_url_service.py
└make_folder_service.py
クラス名・メソッド名
概要
- クラス名は大文字始まりとして、複数の単語を使う場合は2番目以降の単語も大文字始まりとなる(パスカルケース)
- メソッド名は全て小文字・スネークケース
具体例
import urllib.parse
from shared.Domain.xurl import XUrl
# エスケープされた %xx をそれに対応した単一文字に置き換え
class DecodeUrlService:
def execute(self, xurl: XUrl):
return urllib.parse.unquote(xurl.get_href())
以上です