別のpython スクリプトの実行

import スクリプト名

caller.py

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

"""

Created on Fri Jul  2 10:52:10 2021

@author: my name

"""

print('モジュール名:{}'.format(__name__))  #実行したモジュール名を表示する

print('"start"')

import callee

print(callee.add_timestamp('ログ'))

print(callee.add_timestamp.__doc__)

print("'end'")

callee.py

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

"""

Created on Fri Jul  2 10:47:43 2021

@author: akirasakaguchi

"""

print('モジュール名:{}'.format(__name__))  #実行したモジュール名を表示する

import datetime

def add_timestamp(base):

    '''Returns base + time of now'''

    now = datetime.datetime.now()

    return base + '_' + now.strftime('%Y%m%d%H%M%S')

↓結果

runfile('/Users/python/test1/caller.py', wdir='/Users/python/test1')

Reloaded modules: callee

モジュール名:__main__

"start"

モジュール名:callee

ログ_20210819171027

Returns base + time of now

'end'

コメント

人気の投稿