かもメモ

自分の落ちた落とし穴に何度も落ちる人のメモ帳

2018-08-23から1日間の記事一覧

Python3 ファイルの絶対パスを取得したい。

os を使う import os currnet_dir = os.path.dirname( os.path.abspath(__file__) ) os.path.abspath(__file__) で現在のファイルの絶対パスを取得し、os.path.dirname(path)でファイルのあるディレクトリを取得。 参照: 10.1. os.path — 共通のパス名操作 —…

Python3 Classのメモ

classキーワードに続けて大文字から始まるクラス名を記述してクラスを作成する クラスからインスタンスを作成する際はnewなどのキーワードは不要 コンストラクタは__init__()で定義する class Player: # constructor def __init__(self, name = 'Human'): se…