LoginSignup
3
1

More than 3 years have passed since last update.

Glueの使い方的な㊺(Python shellでPythonから他の.pyを読み込む)

Last updated at Posted at 2020-05-21

概要

GlueのPython Shellのコードの中から、別のPythonコードを読み込み実行する

手順

Glueのジョブ作成

Glueの画面で"ジョブ"->[ジョブの追加]をクリックし、以下を入力します。

  • 名前:se2_job28
  • ロール:(適切な任意のもの)
  • Type:Python shell

スクリーンショット 0002-05-21 14.15.44.png

引き続き以下を入力します。以下の"参照されるファイルパス"に内部で読み込むファイル名をS3パスと合わせて記入します。

  • 参照されるファイルパス:s3://test-glue00/se2/script/circle.py(任意のファイルパスとファイル名)

この画面で[次へ]をクリックし、次の画面で[ジョブを保存してスクリプトを編集する]をクリックします。

スクリーンショット 0002-05-21 14.19.00.png

呼び出すコード
S3のs3://test-glue00/se2/script/に配置しておく。

circle.py
def calc_area(r):
 return r ** 2 * 3.14

print('hello circle.py')

ジョブのコード

se2_job28
import circle

# 半径3の円の面積
circle = circle.calc_area(3)
print(circle)

print('hello se2_job28')

ジョブのコードを貼り付け、ジョブを実行します。

スクリーンショット 0002-05-21 14.33.00.png

実行後のログ

呼び出すコードとGlueジョブコードのprintの出力結果が出ている

スクリーンショット 0002-05-21 14.35.26.png

こちらも是非

Glueの使い方まとめ
https://qiita.com/pioho07/items/32f76a16cbf49f9f712f

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1