0
私はPythonでLoggingモジュールを使用する方法を頭に入れようとしています。後続のモジュール呼び出しですでにインポートされたモジュールをPythonで使用する方法
私はメインのコード下記の持っている:
import logging
import First
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(levelname)s %(message)s',filename=r'C:\Users\bhatsubh\Desktop\Everything\Codes\Python\Logs\automation.log',filemode='a')
logging.debug('A debug message')
logging.info('Some information')
logging.warning('A shot across the bows')
logging.error('Committed a blunder')
obj = First.Demo("Subhayan",75000)
print (obj.getSal())
First.pyモジュールは以下のコードが含まれます。
class Demo:
def __init__(self,Name,salary):
logging.info("Inside Demo init")
self.name = Name
self.salary = salary
def getSal(self):
logging.info("Inside Demo getSal")
sal = self.salary * 100
return sal
を今私が一番上にモジュールロギングをインポートすることが可能な何らかの方法があります私のモジュールファイルのレベルを確認し、残りの呼び出しでそれを他のすべてのファイルで再度インポートせずに使用します。
ありがとうございました。
これは実行できますが、両方のファイルでインポートする方がよいでしょう。 –
Stevenさん、ありがとうございます。もう少し詳しく教えてください。私は、両方のファイルをインポートするのがベストプラクティスであると思うが、知識のためには、他の作業はどうなるのだろうか。 –