python

basic

バージョン確認
python --version
post153 >> python --version
Python 3.11.4
モジュールインストール

pip単体で使うとpythonを複数バージョンインストールしている際に不便。

python -m pip install requests
インストールされているモジュール一覧確認
python -m pip list
フォルダ操作
import os

# 実行中のスクリプトのパスを取得
script_path = os.path.abspath(__file__)
print("Script path:", script_path)

# スクリプトのディレクトリを取得
script_directory = os.path.dirname(script_path)
print("Script directory:", script_directory)


# 新しいカレントディレクトリのパスを指定
new_directory = '/path/to/new/directory'

# カレントディレクトリを変更
os.chdir(new_directory)

# 現在のカレントディレクトリを確認
current_directory = os.getcwd()
print("Current directory:", current_directory)
スポンサーリンク
コピペで使う
タイトルとURLをコピーしました