pythonで記述した関数を別ファイルに記述し直してimportする
いつも忘れるのでまとめておく。
pythonのバージョンはpython3.7を利用している。
始めに次のようなコードを考える。
print('Hello! python')
import greeting
greeting.helloworld()
def helloworld(): print('Hello! python')
ここで、greeting.pyを
def helloworld(): print('Hello! python') def hey(): print('hey') def hello(): print('hello')
from greeting import hey hey()